(sem_wait, sem_destroy): Rewritten to use new Mutex and Condition
classes.
* src/threads/posix/thread-posix.hpp [__DARWIN__] (sem_t): Likewise.
- This is a very simple semaphore implementation for darwin. It
+ This is a very simple semaphore implementation for Darwin. It
is implemented in terms of pthreads calls so it isn't async signal
safe. This isn't a problem because signals aren't used to
is implemented in terms of pthreads calls so it isn't async signal
safe. This isn't a problem because signals aren't used to
- suspend threads on darwin.
+ suspend threads on Darwin.
*/
static int sem_init(sem_t *sem, int pshared, int value)
*/
static int sem_init(sem_t *sem, int pshared, int value)
sem->mutex = new Mutex();
sem->mutex = new Mutex();
-
- if (pthread_cond_init(&sem->cond, NULL) < 0)
- return -1;
+ sem->cond = new Condition();
+ sem->value = value;
static int sem_post(sem_t *sem)
{
sem->mutex->lock();
static int sem_post(sem_t *sem)
{
sem->mutex->lock();
-
- if (pthread_cond_signal(&sem->cond) < 0) {
- sem->mutex->unlock();
- return -1;
- }
-
sem->mutex->unlock();
return 0;
sem->mutex->unlock();
return 0;
sem->mutex->lock();
while (sem->value == 0) {
sem->mutex->lock();
while (sem->value == 0) {
-#error We cannot call pthread_cond_wait on a Mutex-class pointer.
- pthread_cond_wait(&sem->cond, &sem->mutex);
+ sem->cond->wait(sem->mutex);
sem->mutex->unlock();
return 0;
sem->mutex->unlock();
return 0;
static int sem_destroy(sem_t *sem)
{
static int sem_destroy(sem_t *sem)
{
- if (pthread_cond_destroy(&sem->cond) < 0)
- return -1;
-
delete sem->mutex;
return 0;
delete sem->mutex;
return 0;
# include <mach/mach.h>
typedef struct {
# include <mach/mach.h>
typedef struct {
- mutex_t mutex;
- pthread_cond_t cond;
+ Mutex* mutex;
+ Condition* cond;