create a new CRON task
| 260 | |
| 261 | // create a new CRON task |
| 262 | CronTaskHandle Cron_AddTask |
| 263 | ( |
| 264 | uint when, // number of miliseconds until task invocation |
| 265 | CronTaskCB work, // callback to call when task is due |
| 266 | CronTaskFree free, // [optional] task private data free function |
| 267 | void *pdata // [optional] private data to pass to callback |
| 268 | ) { |
| 269 | ASSERT(work != NULL); |
| 270 | ASSERT(cron != NULL); |
| 271 | ASSERT(!(free != NULL && pdata == NULL)); |
| 272 | |
| 273 | CRON_TASK *task = rm_malloc(sizeof(CRON_TASK)); |
| 274 | |
| 275 | task->cb = work; |
| 276 | task->due = due_in_ms(when); |
| 277 | task->free = free; |
| 278 | task->pdata = pdata; |
| 279 | |
| 280 | CRON_InsertTask(task); |
| 281 | |
| 282 | return (uintptr_t)task; |
| 283 | } |
| 284 | |
| 285 | // tries to abort given task |
| 286 | // in case task is currently being executed, it will wait for it to finish |