aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/devdraw/cocoa-thread.c
blob: 92b92d2cf855ea4625d82bd89f297a8cf82d7449 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <u.h>
#include <libc.h>
#include "cocoa-thread.h"

#ifndef TRY_LIBTHREAD

static pthread_mutex_t initlock = PTHREAD_MUTEX_INITIALIZER;

void
qlock(QLock *q)
{
	if(q->init == 0){
		pthread_mutex_lock(&initlock);
		if(q->init == 0){
			pthread_mutex_init(&q->m, nil);
			q->init = 1;
		}
		pthread_mutex_unlock(&initlock);
	}
	pthread_mutex_lock(&q->m);
}

void
qunlock(QLock *q)
{
	pthread_mutex_unlock(&q->m);
}

int
threadid(void)
{
	return pthread_mach_thread_np(pthread_self());
}

#endif