Allow user to override pthread mutex and cond

This commit is contained in:
Justine Tunney 2024-12-23 21:57:52 -08:00
parent 4705705548
commit 55b7aa1632
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
54 changed files with 216 additions and 102 deletions

View file

@ -18,6 +18,7 @@
*/
#include "libc/thread/itimer.h"
#include "libc/str/str.h"
#include "libc/thread/posixthread.internal.h"
struct IntervalTimer __itimer = {
.lock = PTHREAD_MUTEX_INITIALIZER,
@ -25,18 +26,18 @@ struct IntervalTimer __itimer = {
};
textwindows void __itimer_lock(void) {
pthread_mutex_lock(&__itimer.lock);
_pthread_mutex_lock(&__itimer.lock);
}
textwindows void __itimer_unlock(void) {
pthread_mutex_unlock(&__itimer.lock);
_pthread_mutex_unlock(&__itimer.lock);
}
textwindows void __itimer_wipe_and_reset(void) {
// timers aren't inherited by forked subprocesses
bzero(&__itimer.it, sizeof(__itimer.it));
pthread_mutex_wipe_np(&__itimer.lock);
pthread_cond_init(&__itimer.cond, 0);
_pthread_mutex_wipe_np(&__itimer.lock);
bzero(&__itimer.cond, sizeof(__itimer.cond));
__itimer.thread = 0;
__itimer.once = 0;
}