| 185 | //------------------------------------------------------------------------------ |
| 186 | |
| 187 | static void *Cron_Run |
| 188 | ( |
| 189 | void *arg |
| 190 | ) { |
| 191 | while(cron->alive) { |
| 192 | // execute due tasks |
| 193 | CRON_TASK *task = NULL; |
| 194 | while((task = CRON_Peek()) && CRON_TaskDue(task)) { |
| 195 | if(!CRON_RemoveCurrentTask(task)) { |
| 196 | // task is aborted |
| 197 | continue; |
| 198 | } |
| 199 | |
| 200 | // perform and free task |
| 201 | CRON_PerformTask(task); |
| 202 | cron->current_task = NULL; |
| 203 | CRON_FreeTask(task); |
| 204 | } |
| 205 | |
| 206 | // sleep |
| 207 | struct timespec timeout = (task) ? task->due : due_in_ms(1000); |
| 208 | pthread_mutex_lock(&cron->condv_mutex); |
| 209 | int res = pthread_cond_timedwait(&cron->condv, &cron->condv_mutex, &timeout); |
| 210 | ASSERT(res == 0 || res == ETIMEDOUT); |
| 211 | pthread_mutex_unlock(&cron->condv_mutex); |
| 212 | } |
| 213 | |
| 214 | return NULL; |
| 215 | } |
| 216 | |
| 217 | //------------------------------------------------------------------------------ |
| 218 | // User facing API |
nothing calls this directly
no test coverage detected