From 07b87f6f1f2d70b51e4493e1cbe33daebc056558 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Sat, 25 Apr 2020 18:58:09 +0200 Subject: [PATCH] pthread: initialize static condition variables Fixes #3741 --- repos/libports/src/lib/libc/pthread.cc | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/repos/libports/src/lib/libc/pthread.cc b/repos/libports/src/lib/libc/pthread.cc index 37b03c0e15..09d0b1710a 100644 --- a/repos/libports/src/lib/libc/pthread.cc +++ b/repos/libports/src/lib/libc/pthread.cc @@ -903,9 +903,12 @@ extern "C" { int pthread_cond_destroy(pthread_cond_t *cond) { - if (!cond || !*cond) + if (!cond) return EINVAL; + if (*cond == PTHREAD_COND_INITIALIZER) + return 0; + Libc::Allocator alloc { }; destroy(alloc, *cond); *cond = 0; @@ -967,9 +970,12 @@ extern "C" { int pthread_cond_signal(pthread_cond_t *cond) { - if (!cond || !*cond) + if (!cond) return EINVAL; + if (*cond == PTHREAD_COND_INITIALIZER) + cond_init(cond, NULL); + pthread_cond *c = *cond; pthread_mutex_lock(&c->counter_mutex); @@ -987,9 +993,12 @@ extern "C" { int pthread_cond_broadcast(pthread_cond_t *cond) { - if (!cond || !*cond) + if (!cond) return EINVAL; + if (*cond == PTHREAD_COND_INITIALIZER) + cond_init(cond, NULL); + pthread_cond *c = *cond; pthread_mutex_lock(&c->counter_mutex);