9front - general discussion about 9front
 help / color / mirror / Atom feed
* etimer() assumes seconds together with APE
@ 2020-05-12 15:09 jamos
  2020-05-12 15:34 ` [9front] " Steve Simon
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: jamos @ 2020-05-12 15:09 UTC (permalink / raw)
  To: 9front

Dear list,

The function etimer(ulong key, int n) is used in libevent to get a timer 
event every 'n' milliseconds. However, if APE is used, etimer() delivers 
an event every 'n' second instead. The reason is that sleep() assumes 
seconds in APE and milliseconds in Plan 9.

I am aware that combining Plan 9 libraries with APE is a bit risky. When 
I earlier wanted to use etimer() in the netsurf framebuffer driver, I 
assumed it didn't work under APE, but I was not patient enough to wait 
1000 seconds, when I thought it would fire after one second.

Would this be considered a bug? It would be more consistent if etimer() 
would take milliseconds as well under APE, and it would also be more 
handy if one would like to sleep less than a second. I tried to find APE 
programs that might depend on the current behaviour, but I don't think 
there are many.

The following test program prints a string every 10 seconds (in APE) and 
every 10ms (if it can manage) under native Plan9. Stop by killing the 
processes.

/* Compile under native plan9:
  * 	8c ev.c; 8l -o native ev.8
  *
  * Compile under APE:
  * 	pcc  -D_POSIX_SOURCE -D_PLAN9_SOURCE -o posix ev.c
  */

#include <u.h>
#ifdef _POSIX_SOURCE
	#include <stdlib.h>
#else
	#include <libc.h>
#endif
#include <draw.h>
#include <event.h>

void
eresized(int) {}

void
main()
{
	int tim;	/* timer ticket */
	int e;		/* type of event */
	Event ev;	/* event struct */

	initdraw(0, 0, "timer test");
	einit(Ekeyboard|Emouse);
	tim = etimer(0, 10);	/* 10ms or 10s?*/
	for(;;){
		e = event(&ev);
		if(e == tim)
			print("Timer!\n");

	}
}


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-05-12 22:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-12 15:09 etimer() assumes seconds together with APE jamos
2020-05-12 15:34 ` [9front] " Steve Simon
2020-05-12 15:39 ` ori
2020-05-12 22:05   ` cinap_lenrek
2020-05-12 22:12     ` ori
2020-05-12 22:16 ` cinap_lenrek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).