#include <pthread.h>

#define NODEFINE
#include <u.h>
#include <libc.h>


static void*
newpthread(void *v)
{
	Pmproc *p;
	struct { void (*fn)(void*); void *arg; } *a;
	void (*fn)(void*);
	void *arg;

	p = pm_mallocz(sizeof(*p), 1);
	pm_setup(p);
	
	a = v;
	fn = a->fn;
	arg = a->arg;
	pm_free(a);
	(*fn)(arg);
	pthread_exit(nil);
	return nil;
}

void
pm_proc(void (*fn)(void*), void *arg, uint stacksize)
{
	struct { void (*fn)(void*); void *arg; } *a;
	pthread_t id;

	USED(stacksize);
	a = pm_malloc(sizeof(*a));
	a->fn = fn;
	a->arg = arg;
	if(pthread_create(&id, nil, newpthread, a) != 0)
		pm_panic("pmproc");
}

