#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
