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