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.
This commit is contained in:
parent
b8be64c43d
commit
3990c5c6a4
7 changed files with 22 additions and 31 deletions
|
|
@ -3,10 +3,11 @@
|
|||
|
||||
int timer_delete(timer_t t)
|
||||
{
|
||||
if (t->thread) pthread_cancel(t->thread);
|
||||
else {
|
||||
__syscall(SYS_timer_delete, t->timerid);
|
||||
free(t);
|
||||
}
|
||||
return 0;
|
||||
pthread_t td = 0;
|
||||
int r;
|
||||
if ((uintptr_t)t & 1) t = (void *)((unsigned long)t / 2);
|
||||
else td = t, t = td->result;
|
||||
r = __syscall(SYS_timer_delete, (long)t);
|
||||
if (td) pthread_cancel(td);
|
||||
return r;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue