blob: 7a374bb95a1d9167b43b3e0d088fe20e42a08f6e (
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
/*
* create.c
*
* Description:
* This translation unit implements routines associated with spawning a new
* thread.
*/
#include "pthread.h"
#include "implement.h"
/* FIXME: There must be a Win32 routine to get this value. */
DWORD pthread_threads_count = 0;
int
pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void * (*start_routine) (void *), void * arg)
{
/* Call Win32 CreateThread.
Map attributes as correctly as possible.
*/
HANDLE handle;
DWORD flags = 0; /* Always 0 for POSIX threads */
DWORD stack = PTHREAD_STACK_MIN;
LPSECURITY_ATTRIBUTES security = NULL;
/* FIXME: This needs to be moved into process space.
Perhaps into a structure that contains all
per thread info that is Win32 thread specific but
not visible from the pthreads API, and
accessible through HANDLE (or pthread_t).
*/
SECURITY_ATTRIBUTES security_attr;
DWORD threadID;
if (pthread_threads_count >= PTHREAD_THREADS_MAX)
return EAGAIN;
switch (attr)
{
case NULL:
/* Use POSIX default attributes */
break;
default:
/* Map attributes */
if (attr->stacksize != NULL)
stack = (DWORD) attr->stacksize;
break;
}
/* FIXME: I don't have error return values to work with so
I'm assuming this always succeeds (obviously not).
*/
handle = CreateThread(security,
stack,
start_routine,
arg,
flags,
&threadID);
*thread = (pthread_t) handle;
pthread_threads_count++;
return 0;
}
|