/src/test/timer_test.c

http://ftk.googlecode.com/ · C · 34 lines · 28 code · 6 blank · 0 comment · 4 complexity · 28c96b104766d6d27c7f7b7b98112c7b MD5 · raw file

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