PageRenderTime 7ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/timer_test.c

http://ftk.googlecode.com/
C | 34 lines | 28 code | 6 blank | 0 comment | 3 complexity | 28c96b104766d6d27c7f7b7b98112c7b MD5 | raw file
 1#include "ftk.h"
 2
 3Ret my_action(void* user_data)
 4{	
 5	int* p = (int*)user_data;
 6
 7	(*p)++;
 8	printf("%d\n", *p);
 9
10	return *p == 10 ? RET_REMOVE:RET_OK;
11}
12
13int main(int argc, char* argv[])
14{
15	int n = 0;
16
17	ftk_set_allocator(ftk_allocator_default_create());
18	FtkSource* thiz = ftk_source_timer_create(1500, my_action, &n);
19	while(1)
20	{
21		int t = ftk_source_check(thiz);
22		printf("t=%d\n", t);
23		assert(t > 1000);
24		assert(ftk_source_get_fd(thiz) < 0);
25		usleep(t*1000);
26		if(ftk_source_dispatch(thiz) == RET_REMOVE)
27		{
28			break;
29		}
30	}
31	ftk_source_unref(thiz);
32
33	return 0;
34}