Back to index

plt-scheme  4.2.1
Classes | Functions
darwin_semaphore.h File Reference

Go to the source code of this file.

Classes

struct  sem_t

Functions

static int sem_init (sem_t *sem, int pshared, int value)
static int sem_post (sem_t *sem)
static int sem_wait (sem_t *sem)
static int sem_destroy (sem_t *sem)

Class Documentation

struct sem_t

Definition at line 15 of file darwin_semaphore.h.

Class Members
pthread_cond_t cond
pthread_mutex_t mutex
int value

Function Documentation

static int sem_destroy ( sem_t sem) [static]

Definition at line 59 of file darwin_semaphore.h.

                                   {
    int ret;
    ret = pthread_cond_destroy(&sem->cond);
    if(ret < 0) return -1;
    ret = pthread_mutex_destroy(&sem->mutex);
    if(ret < 0) return -1;
    return 0;
}
static int sem_init ( sem_t sem,
int  pshared,
int  value 
) [static]

Definition at line 21 of file darwin_semaphore.h.

                                                        {
    int ret;
    if(pshared)
        GC_abort("sem_init with pshared set");
    sem->value = value;
    
    ret = pthread_mutex_init(&sem->mutex,NULL);
    if(ret < 0) return -1;
    ret = pthread_cond_init(&sem->cond,NULL);
    if(ret < 0) return -1;
    return 0;
}

Here is the call graph for this function:

static int sem_post ( sem_t sem) [static]

Definition at line 34 of file darwin_semaphore.h.

                                {
    if(pthread_mutex_lock(&sem->mutex) < 0)
        return -1;
    sem->value++;
    if(pthread_cond_signal(&sem->cond) < 0) {
        pthread_mutex_unlock(&sem->mutex);
        return -1;
    }
    if(pthread_mutex_unlock(&sem->mutex) < 0)
        return -1;
    return 0;
}
static int sem_wait ( sem_t sem) [static]

Definition at line 47 of file darwin_semaphore.h.

                                {
    if(pthread_mutex_lock(&sem->mutex) < 0)
        return -1;
    while(sem->value == 0) {
        pthread_cond_wait(&sem->cond,&sem->mutex);
    }
    sem->value--;
    if(pthread_mutex_unlock(&sem->mutex) < 0)
        return -1;    
    return 0;
}