diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-21 17:21:26 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2007-03-21 17:21:26 +0000 |
commit | 9539b686d25f82b5a9938725c6fe2c2ac862e632 (patch) | |
tree | 15bd94438dbb8fd1f655598700f34c79dd3af092 /nuttx/sched/timer_delete.c | |
parent | 7407828071d3d8f8d15f4e99e34114208e97bc33 (diff) | |
download | px4-nuttx-9539b686d25f82b5a9938725c6fe2c2ac862e632.tar.gz px4-nuttx-9539b686d25f82b5a9938725c6fe2c2ac862e632.tar.bz2 px4-nuttx-9539b686d25f82b5a9938725c6fe2c2ac862e632.zip |
Added support for POSIX timers
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@111 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/sched/timer_delete.c')
-rw-r--r-- | nuttx/sched/timer_delete.c | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/nuttx/sched/timer_delete.c b/nuttx/sched/timer_delete.c index 4dc97a9bd..aed19f76a 100644 --- a/nuttx/sched/timer_delete.c +++ b/nuttx/sched/timer_delete.c @@ -39,7 +39,10 @@ #include <nuttx/config.h> #include <time.h> +#include <queue.h> #include <errno.h> +#include <nuttx/kmalloc.h> +#include "timer_internal.h" #ifndef CONFIG_DISABLE_POSIX_TIMERS @@ -60,6 +63,43 @@ ********************************************************************************/ /******************************************************************************** + * Function: timer_free + * + * Description: + * Remove the timer from the allocated timer list and free it or return it to + * the free list (depending on whether or not the timer is one of the + * preallocated timers) + * + ********************************************************************************/ + +static void timer_free(struct posix_timer_s *timer) +{ + irqstate_t flags; + + /* Remove the timer from the allocated list */ + + flags = irqsave(); + sq_rem((FAR sq_entry_t*)timer, (sq_queue_t*)&g_alloctimers); + + /* Return it to the free list if it is one of the preallocated timers */ + +#if CONFIG_PREALLOC_TIMERS > 0 + if ((timer->pt_flags & PT_FLAGS_PREALLOCATED) != 0) + { + sq_addlast((FAR sq_entry_t*)&timer, (FAR sq_queue_t*)&g_freetimers); + irqrestore(flags); + } + else +#endif + { + /* Otherwise, return it to the heap */ + + irqrestore(flags); + sched_free(timer); + } +} + +/******************************************************************************** * Public Functions ********************************************************************************/ @@ -88,8 +128,24 @@ int timer_delete(timer_t timerid) { -#warning "Not Implemented" - return ENOTSUP; + FAR struct posix_timer_s *timer = (FAR struct posix_timer_s *)timerid; + + /* Some sanity checks */ + + if (!timer) + { + *get_errno_ptr() = EINVAL; + return ERROR; + } + + /* Disarm the timer */ + + (void)wd_cancel(timer->pt_wdog); + + /* Release the timer structure */ + + timer_free(timer); + return OK; } #endif /* CONFIG_DISABLE_POSIX_TIMERS */ |