static void Frames_CallFunc( LCUI_Frames *frames ) { int i, total; LCUI_Func *func; LCUI_Graph *slot; total = Queue_GetTotal( &frames->func_data ); slot = Frames_GetGraphSlot( frames ); for(i=0; i<total; ++i){ func = Queue_Get( &frames->func_data, i ); func->arg[0] = slot; AppTasks_CustomAdd( ADD_MODE_REPLACE | AND_ARG_S, func ); } }
/** 定时器线程,用于处理列表中各个定时器 */ static void TimerThread( void *arg ) { int i, n; long int n_ms; LCUI_Func func_data; LCUI_Queue *timer_list; timer_data *timer = NULL; int64_t lost_ms; timer_list = (LCUI_Queue*)arg; func_data.arg[0] = NULL; func_data.arg[1] = NULL; while( !LCUI_Active() ) { LCUI_MSleep(10); } while( timer_thread_active ) { Queue_Lock( timer_list ); n = Queue_GetTotal( timer_list ); for(i=0; i<n; ++i) { timer = (timer_data*)Queue_Get( timer_list , i); if( !timer ) { continue; } if( timer->state == STATE_RUN ) { break; } } Queue_Unlock( timer_list ); /* 没有要处理的定时器,停留一段时间再进行下次循环 */ if(i >= n || !timer ) { LCUI_MSleep(10); continue; } lost_ms = LCUI_GetTicks( timer->start_time ); /* 减去处于暂停状态的时长 */ lost_ms -= timer->pause_ms; /* 若流失的时间未达到总定时时长 */ if( lost_ms < timer->total_ms ) { Queue_Lock( timer_list ); n_ms = timer->total_ms - lost_ms; /* 开始睡眠 */ LCUISleeper_StartSleep( &timer_sleeper, n_ms ); Queue_Unlock( timer_list ); lost_ms = LCUI_GetTicks( timer->start_time ); lost_ms -= timer->pause_ms; if( lost_ms < timer->total_ms ) { continue; } } DEBUG_MSG("timer: %d, start_time: %I64dms, cur_time: %I64dms, cur_ms: %I64d, total_ms: %ld\n", timer->id, timer->start_time, LCUI_GetTickCount(), timer->total_ms-lost_ms, timer->total_ms); /* 准备任务数据 */ func_data.id = timer->app_id; func_data.func = (CallBackFunc)timer->callback_func; func_data.arg[0] = timer->arg; func_data.destroy_arg[0] = FALSE; /* 添加该任务至指定程序的任务队列,添加模式是覆盖 */ AppTasks_CustomAdd( ADD_MODE_REPLACE | AND_ARG_F, &func_data ); Queue_Lock( timer_list ); /* 若需要重复使用,则重置剩余等待时间 */ if( timer->reuse ) { timer->start_time = LCUI_GetTickCount(); timer->pause_ms = 0; TimerList_UpdateTimerPos( timer_list, timer ); } else { /* 否则,释放该定时器 */ LCUITimer_Free( timer->id ); } Queue_Unlock( timer_list ); } LCUIThread_Exit(NULL); }