shithub: libvpx

ref: 3ccbd4803bcc75be860dd67bb3a56b114251433b
dir: /plan9/pthread.h/

View raw version
#ifndef __pthread_h__
#define __pthread_h__

typedef struct pthread_t pthread_t;
typedef struct pthread_cond_t pthread_cond_t;
typedef struct pthread_once_t pthread_once_t;
typedef struct pthread_mutex_t pthread_mutex_t;

struct pthread_cond_t {
    Rendez;
    QLock lock;
};

struct pthread_once_t {
	QLock;
	int done;
};

struct pthread_mutex_t {
	QLock;
};

#define PTHREAD_ONCE_INIT {0}

struct pthread_t {
    void *waitchan;
    void *(*func)(void*);
    void *arg;
    int pid;
};

typedef struct {
    unsigned stack_size;
} pthread_attr_t;

void dav1d_set_thread_name(const char *const name);
int dav1d_pthread_join(pthread_t *thread, void **res);
#define pthread_join(thread, res) dav1d_pthread_join(&(thread), res)

static int pthread_attr_init(pthread_attr_t *const attr) {
    attr->stack_size = 0;
    return 0;
}

static int pthread_attr_destroy(pthread_attr_t *const attr) {
	USED(attr);
    return 0;
}

static int pthread_attr_setstacksize(pthread_attr_t *const attr,
                                     const int stack_size)
{
    attr->stack_size = stack_size;
    return 0;
}

static int
pthread_mutex_trylock(pthread_mutex_t *const mutex)
{
    return canqlock(mutex) ? 0 : -1;
}

int pthread_mutex_init(pthread_mutex_t *const mutex, const void *const attr);
int pthread_mutex_destroy(pthread_mutex_t *const mutex);
int pthread_mutex_lock(pthread_mutex_t *const mutex);
int pthread_mutex_unlock(pthread_mutex_t *const mutex);
int pthread_cond_init(pthread_cond_t *const cond, const void *const attr);
int pthread_cond_destroy(pthread_cond_t *const cond);
int pthread_cond_wait(pthread_cond_t *const cond, pthread_mutex_t *const mutex);
int pthread_cond_signal(pthread_cond_t *const cond);
int pthread_cond_broadcast(pthread_cond_t *const cond);
int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*func)(void*), void *arg);
int pthread_once(pthread_once_t *once_control, void (*init_routine)(void));

#endif