139 lines · 2.1 KB · C
RawDownload
#include <u.h>#include <libc.h>#include </sys/include/thread.h>#include "thread.h" enum {	Magic = 1325465,}; voiddav1d_set_thread_name(const char *const name){	threadsetname(name);} static voidthre(void *x){	pthread_t *t;	void *p; 	t = x;	p = t->func(t->arg);	send(t->waitchan, p);	threadexits(nil);} intpthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*func)(void*), void *arg){	int stacksz = attr == nil ? 0 : attr->stack_size;	if(stacksz < 65536)		stacksz = 65536;	thread->waitchan = chancreate(sizeof(void*), 0);	thread->func = func;	thread->arg = arg;	thread->pid = proccreate(thre, thread, stacksz); 	return 0;} intdav1d_pthread_join(pthread_t *thread, void **res){	// FIXME this is wrong ofc	if (thread->waitchan != nil) {		recv(thread->waitchan, res);		chanfree(thread->waitchan);		thread->waitchan = nil;	} 	return 0;} intpthread_once(pthread_once_t *once, void (*init_routine)(void)){	qlock(once);	if (once->done != Magic) {		init_routine();		once->done = Magic;	}	qunlock(once);	return 0;} intpthread_mutex_init(pthread_mutex_t *const mutex, const void *const attr){	USED(attr);	memset(mutex, 0, sizeof(*mutex));    return 0;} intpthread_mutex_destroy(pthread_mutex_t *const mutex){	USED(mutex);    return 0;} intpthread_mutex_lock(pthread_mutex_t *const mutex){    qlock(mutex);    return 0;} intpthread_mutex_unlock(pthread_mutex_t *const mutex){    qunlock(mutex);    return 0;} intpthread_cond_init(pthread_cond_t *const cond, const void *const attr){	USED(attr);    memset(cond, 0, sizeof(*cond));    cond->l = &cond->lock;    return 0;} intpthread_cond_destroy(pthread_cond_t *const cond){	USED(cond);    return 0;} intpthread_cond_wait(pthread_cond_t *const cond, pthread_mutex_t *const mutex){	qlock(cond->l);	qunlock(mutex);	rsleep(cond);	qunlock(cond->l);	qlock(mutex);    return 0;} intpthread_cond_signal(pthread_cond_t *const cond){	qlock(cond->l);	rwakeup(cond);	qunlock(cond->l);    return 0;} intpthread_cond_broadcast(pthread_cond_t *const cond){	qlock(cond->l);	rwakeupall(cond);	qunlock(cond->l);    return 0;}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t