Generate Perl modules defining prototypes for exported functions.
[wine] / dlls / msvcrt / thread.c
1 /*
2  * msvcrt.dll thread functions
3  *
4  * Copyright 2000 Jon Griffiths
5  */
6 #include "msvcrt.h"
7
8 #include "msvcrt/malloc.h"
9 #include "msvcrt/process.h"
10
11 DEFAULT_DEBUG_CHANNEL(msvcrt);
12
13 /********************************************************************/
14
15 typedef struct {
16   _beginthread_start_routine_t start_address;
17   void *arglist;
18 } _beginthread_trampoline_t;
19
20 /*********************************************************************
21  *              _beginthread_trampoline
22  */
23 static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
24 {
25     _beginthread_trampoline_t local_trampoline;
26
27     /* Maybe it's just being paranoid, but freeing arg right 
28      * away seems safer. 
29      */
30     memcpy(&local_trampoline,arg,sizeof(local_trampoline));
31     MSVCRT_free(arg);
32
33     local_trampoline.start_address(local_trampoline.arglist);
34     return 0;
35 }
36
37 /*********************************************************************
38  *              _beginthread (MSVCRT.@)
39  */
40 unsigned long _beginthread(
41   _beginthread_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
42   unsigned int stack_size, /* [in] Stack size for new thread or 0 */
43   void *arglist)           /* [in] Argument list to be passed to new thread or NULL */
44 {
45   _beginthread_trampoline_t* trampoline;
46
47   TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
48
49   /* Allocate the trampoline here so that it is still valid when the thread 
50    * starts... typically after this function has returned.
51    * _beginthread_trampoline is responsible for freeing the trampoline
52    */
53   trampoline=MSVCRT_malloc(sizeof(*trampoline));
54   trampoline->start_address = start_address;
55   trampoline->arglist = arglist;
56
57   /* FIXME */
58   return CreateThread(NULL, stack_size, _beginthread_trampoline, trampoline, 0, NULL);
59 }
60
61 /*********************************************************************
62  *              _beginthreadex (MSVCRT.@)
63  */
64 unsigned long _beginthreadex(
65   void *security,          /* [in] Security descriptor for new thread; must be NULL for Windows 9x applications */
66   unsigned int stack_size, /* [in] Stack size for new thread or 0 */
67   _beginthreadex_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
68   void *arglist,           /* [in] Argument list to be passed to new thread or NULL */
69   unsigned int initflag,   /* [in] Initial state of new thread (0 for running or CREATE_SUSPEND for suspended) */
70   unsigned int *thrdaddr)  /* [out] Points to a 32-bit variable that receives the thread identifier */
71 {
72   TRACE("(%p, %d, %p, %p, %d, %p)\n", security, stack_size, start_address, arglist, initflag, thrdaddr);
73
74   /* FIXME */
75   return CreateThread(security, stack_size, (LPTHREAD_START_ROUTINE) start_address,
76                       arglist, initflag, (LPDWORD) thrdaddr);
77 }
78
79 /*********************************************************************
80  *              _endthread (MSVCRT.@)
81  */
82 void _endthread(void)
83 {
84   TRACE("(void)\n");
85
86   /* FIXME */
87   ExitThread(0);
88 }
89
90 /*********************************************************************
91  *              _endthreadex (MSVCRT.@)
92  */
93 void _endthreadex(
94   unsigned int retval) /* [in] Thread exit code */
95 {
96   TRACE("(%d)\n", retval);
97
98   /* FIXME */
99   ExitThread(retval);
100 }
101