path: root/src/time/timer_settime.c
diff options
authorRich Felker <>2011-03-30 13:04:55 -0400
committerRich Felker <>2011-03-30 13:04:55 -0400
commit3990c5c6a40440cdb14746ac080d0ecf8d5d6733 (patch)
treeb20dd1257972fdbe84202e9b6c913e90c1fa1d54 /src/time/timer_settime.c
parentb8be64c43da207a2f497c1c5b5720e4a2027348a (diff)
avoid all malloc/free in timer creation/destruction
instead of allocating a userspace structure for signal-based timers, simply use the kernel timer id. we use the fact that thread pointers will always be zero in the low bit (actually more) to encode integer timerid values as pointers. also, this change ensures that the timer_destroy syscall has completed before the library timer_destroy function returns, in case it matters.
Diffstat (limited to 'src/time/timer_settime.c')
1 files changed, 3 insertions, 1 deletions
diff --git a/src/time/timer_settime.c b/src/time/timer_settime.c
index d109570b..00708f0e 100644
--- a/src/time/timer_settime.c
+++ b/src/time/timer_settime.c
@@ -3,5 +3,7 @@
int timer_settime(timer_t t, int flags, const struct itimerspec *val, struct itimerspec *old)
- return syscall(SYS_timer_settime, t->timerid, flags, val, old);
+ if ((uintptr_t)t & 1) t = (void *)((unsigned long)t / 2);
+ else t = ((pthread_t)t)->result;
+ return syscall(SYS_timer_settime, (long)t, flags, val, old);