timer.inl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. struct timers {
  2. pthread_t timerthreadid; /* Time thread ID */
  3. pthread_mutex_t timer_mutex; /* Protects timer lists */
  4. struct timer_list *timers; /* List of timers */
  5. };
  6. static void timer_thread_run(void *thread_func_param)
  7. {
  8. struct mg_context *ctx = (struct mg_context *) thread_func_param;
  9. while (ctx->stop_flag == 0) {
  10. pthread_mutex_lock(&ctx->timer_mutex);
  11. /* TODO: something useful */
  12. pthread_mutex_unlock(&ctx->timer_mutex);
  13. mg_sleep(1);
  14. }
  15. }
  16. static int timer_add(struct mg_context * ctx, double rel_time, int is_periodic, const char * action)
  17. {
  18. pthread_mutex_lock(&ctx->timer_mutex);
  19. /* TODO: something useful */
  20. pthread_mutex_unlock(&ctx->timer_mutex);
  21. return 0;
  22. }
  23. #ifdef _WIN32
  24. static unsigned __stdcall timer_thread(void *thread_func_param)
  25. {
  26. timer_thread_run(thread_func_param);
  27. return 0;
  28. }
  29. #else
  30. static void *timer_thread(void *thread_func_param)
  31. {
  32. timer_thread_run(thread_func_param);
  33. return NULL;
  34. }
  35. #endif /* _WIN32 */
  36. static int timers_init(struct mg_context * ctx)
  37. {
  38. (void) pthread_mutex_init(&ctx->timer_mutex, NULL);
  39. /* Start timer thread */
  40. mg_start_thread_with_id(timer_thread, ctx, &ctx->timerthreadid);
  41. return 0;
  42. }
  43. static void timers_exit(struct mg_context * ctx)
  44. {
  45. (void) pthread_mutex_destroy(&ctx->timer_mutex);
  46. }