mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-28 15:52:39 +02:00
Use revised CondVar API in C11 threads impl
This commit is contained in:
parent
1e349b6ce8
commit
b181d725ac
@ -2,6 +2,7 @@
|
|||||||
#include "../switch/types.h"
|
#include "../switch/types.h"
|
||||||
#include "../switch/result.h"
|
#include "../switch/result.h"
|
||||||
#include "../switch/kernel/mutex.h"
|
#include "../switch/kernel/mutex.h"
|
||||||
|
#include "../switch/kernel/condvar.h"
|
||||||
#include "../switch/kernel/thread.h"
|
#include "../switch/kernel/thread.h"
|
||||||
|
|
||||||
#define TSS_DTOR_ITERATIONS 1
|
#define TSS_DTOR_ITERATIONS 1
|
||||||
@ -11,7 +12,7 @@ typedef struct {
|
|||||||
int rc;
|
int rc;
|
||||||
} __thrd_t;
|
} __thrd_t;
|
||||||
|
|
||||||
typedef u32 cnd_t;
|
typedef CondVar cnd_t;
|
||||||
typedef __thrd_t* thrd_t;
|
typedef __thrd_t* thrd_t;
|
||||||
typedef u32 tss_t;
|
typedef u32 tss_t;
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ int cnd_broadcast(cnd_t *cond)
|
|||||||
if (!cond)
|
if (!cond)
|
||||||
return thrd_error;
|
return thrd_error;
|
||||||
|
|
||||||
Result rc = svcSignalProcessWideKey(cond, -1);
|
Result rc = condvarWakeAll(cond);
|
||||||
return R_SUCCEEDED(rc) ? thrd_success : thrd_error;
|
return R_SUCCEEDED(rc) ? thrd_success : thrd_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ int cnd_init(cnd_t *cond)
|
|||||||
if (!cond)
|
if (!cond)
|
||||||
return thrd_error;
|
return thrd_error;
|
||||||
|
|
||||||
*cond = 0;
|
condvarInit(cond);
|
||||||
return thrd_success;
|
return thrd_success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ int cnd_signal(cnd_t *cond)
|
|||||||
if (!cond)
|
if (!cond)
|
||||||
return thrd_error;
|
return thrd_error;
|
||||||
|
|
||||||
Result rc = svcSignalProcessWideKey(cond, 1);
|
Result rc = condvarWakeOne(cond);
|
||||||
return R_SUCCEEDED(rc) ? thrd_success : thrd_error;
|
return R_SUCCEEDED(rc) ? thrd_success : thrd_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,13 +64,7 @@ static int __cnd_timedwait(cnd_t *__restrict cond, mtx_t *__restrict mtx, u64 ti
|
|||||||
if (!cond || !mtx || mtx->type != mtx_plain)
|
if (!cond || !mtx || mtx->type != mtx_plain)
|
||||||
return thrd_error;
|
return thrd_error;
|
||||||
|
|
||||||
Result rc = svcWaitProcessWideKeyAtomic((u32*)&mtx->mutex, cond, getThreadVars()->handle, timeout);
|
Result rc = condvarWaitTimeout(cond, &mtx->mutex, timeout);
|
||||||
|
|
||||||
// On timeout, we need to acquire it manually.
|
|
||||||
if (rc == 0xEA01) {
|
|
||||||
mutexLock(&mtx->mutex);
|
|
||||||
return thrd_busy;
|
|
||||||
}
|
|
||||||
|
|
||||||
return R_SUCCEEDED(rc) ? thrd_success : thrd_error;
|
return R_SUCCEEDED(rc) ? thrd_success : thrd_error;
|
||||||
}
|
}
|
||||||
@ -285,8 +279,7 @@ int thrd_sleep(const struct timespec *duration, struct timespec *remaining)
|
|||||||
|
|
||||||
void thrd_yield(void)
|
void thrd_yield(void)
|
||||||
{
|
{
|
||||||
// This is trash.
|
svcSleepThread(-1);
|
||||||
svcSleepThread(10000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user