11 changes: 8 additions & 3 deletions libc/src/threads/linux/cnd_broadcast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
//
//===----------------------------------------------------------------------===//

#include "CndVar.h"

#include "src/threads/cnd_broadcast.h"
#include "src/__support/common.h"
#include "src/__support/threads/CndVar.h"

// TODO: https://github.com/llvm/llvm-project/issues/92968
#include <threads.h> // cnd_t, thrd_error, thrd_success

namespace LIBC_NAMESPACE {

static_assert(sizeof(CndVar) == sizeof(cnd_t));

LLVM_LIBC_FUNCTION(int, cnd_broadcast, (cnd_t * cond)) {
CndVar *cndvar = reinterpret_cast<CndVar *>(cond);
return cndvar->broadcast();
cndvar->broadcast();
return thrd_success;
}

} // namespace LIBC_NAMESPACE
7 changes: 5 additions & 2 deletions libc/src/threads/linux/cnd_destroy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
//
//===----------------------------------------------------------------------===//

#include "CndVar.h"

#include "src/threads/cnd_destroy.h"
#include "src/__support/common.h"
#include "src/__support/threads/CndVar.h"

#include <threads.h> // cnd_t

namespace LIBC_NAMESPACE {

static_assert(sizeof(CndVar) == sizeof(cnd_t));

LLVM_LIBC_FUNCTION(void, cnd_destroy, (cnd_t * cond)) {
CndVar *cndvar = reinterpret_cast<CndVar *>(cond);
CndVar::destroy(cndvar);
Expand Down
9 changes: 6 additions & 3 deletions libc/src/threads/linux/cnd_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
//
//===----------------------------------------------------------------------===//

#include "CndVar.h"

#include "src/threads/cnd_init.h"
#include "src/__support/common.h"
#include "src/__support/threads/CndVar.h"

#include <threads.h> // cnd_t, thrd_error, thrd_success

namespace LIBC_NAMESPACE {

static_assert(sizeof(CndVar) == sizeof(cnd_t));

LLVM_LIBC_FUNCTION(int, cnd_init, (cnd_t * cond)) {
CndVar *cndvar = reinterpret_cast<CndVar *>(cond);
return CndVar::init(cndvar);
return CndVar::init(cndvar) ? thrd_error : thrd_success;
}

} // namespace LIBC_NAMESPACE
10 changes: 7 additions & 3 deletions libc/src/threads/linux/cnd_signal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
//
//===----------------------------------------------------------------------===//

#include "CndVar.h"

#include "src/threads/cnd_signal.h"
#include "src/__support/common.h"
#include "src/__support/threads/CndVar.h"

#include <threads.h> // cnd_t, thrd_error, thrd_success

namespace LIBC_NAMESPACE {

static_assert(sizeof(CndVar) == sizeof(cnd_t));

LLVM_LIBC_FUNCTION(int, cnd_signal, (cnd_t * cond)) {
CndVar *cndvar = reinterpret_cast<CndVar *>(cond);
return cndvar->notify_one();
cndvar->notify_one();
return thrd_success;
}

} // namespace LIBC_NAMESPACE
11 changes: 7 additions & 4 deletions libc/src/threads/linux/cnd_wait.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@
//
//===----------------------------------------------------------------------===//

#include "CndVar.h"

#include "src/threads/cnd_wait.h"
#include "src/__support/common.h"
#include "src/__support/threads/CndVar.h"
#include "src/__support/threads/mutex.h"
#include "src/threads/cnd_wait.h"

#include <threads.h> // cnd_t, mtx_t, thrd_error, thrd_success

namespace LIBC_NAMESPACE {

static_assert(sizeof(CndVar) == sizeof(cnd_t));

LLVM_LIBC_FUNCTION(int, cnd_wait, (cnd_t * cond, mtx_t *mtx)) {
CndVar *cndvar = reinterpret_cast<CndVar *>(cond);
Mutex *mutex = reinterpret_cast<Mutex *>(mtx);
return cndvar->wait(mutex);
return cndvar->wait(mutex) ? thrd_error : thrd_success;
}

} // namespace LIBC_NAMESPACE