aboutsummaryrefslogtreecommitdiff
path: root/src/lib9/ffork-pthread.c
blob: c89ad138682a197544a1d7755dc71e77b7a35031 (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
#define NOPLAN9DEFINES
#include <u.h>
#include <libc.h>
#include <pthread.h>
#include "9proc.h"

extern int __isthreaded;
int
ffork(int flags, void(*fn)(void*), void *arg)
{
	pthread_t tid;

	if(flags != (RFMEM|RFNOWAIT)){
		werrstr("ffork unsupported");
		return -1;
	}

	_p9uproc(0);
	if(pthread_create(&tid, NULL, (void*(*)(void*))fn, arg) < 0)
		return -1;
	if((int)tid == 0)
		_p9uproc(0);
	return (int)tid;
}

int
getfforkid(void)
{
	return (int)pthread_self();
}