Added regedit unit test, a couple minor changes to regedit.
[wine] / dlls / msvcrt / thread.c
1 /*
2  * msvcrt.dll thread functions
3  *
4  * Copyright 2000 Jon Griffiths
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 #include "msvcrt.h"
21
22 #include "msvcrt/malloc.h"
23 #include "msvcrt/process.h"
24
25 #include "wine/debug.h"
26
27 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
28
29 /********************************************************************/
30
31 typedef struct {
32   _beginthread_start_routine_t start_address;
33   void *arglist;
34 } _beginthread_trampoline_t;
35
36 /*********************************************************************
37  *              _beginthread_trampoline
38  */
39 static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
40 {
41     _beginthread_trampoline_t local_trampoline;
42
43     /* Maybe it's just being paranoid, but freeing arg right
44      * away seems safer.
45      */
46     memcpy(&local_trampoline,arg,sizeof(local_trampoline));
47     MSVCRT_free(arg);
48
49     local_trampoline.start_address(local_trampoline.arglist);
50     return 0;
51 }
52
53 /*********************************************************************
54  *              _beginthread (MSVCRT.@)
55  */
56 unsigned long _beginthread(
57   _beginthread_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
58   unsigned int stack_size, /* [in] Stack size for new thread or 0 */
59   void *arglist)           /* [in] Argument list to be passed to new thread or NULL */
60 {
61   _beginthread_trampoline_t* trampoline;
62
63   TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
64
65   /* Allocate the trampoline here so that it is still valid when the thread
66    * starts... typically after this function has returned.
67    * _beginthread_trampoline is responsible for freeing the trampoline
68    */
69   trampoline=MSVCRT_malloc(sizeof(*trampoline));
70   trampoline->start_address = start_address;
71   trampoline->arglist = arglist;
72
73   /* FIXME */
74   return CreateThread(NULL, stack_size, _beginthread_trampoline, trampoline, 0, NULL);
75 }
76
77 /*********************************************************************
78  *              _beginthreadex (MSVCRT.@)
79  */
80 unsigned long _beginthreadex(
81   void *security,          /* [in] Security descriptor for new thread; must be NULL for Windows 9x applications */
82   unsigned int stack_size, /* [in] Stack size for new thread or 0 */
83   _beginthreadex_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
84   void *arglist,           /* [in] Argument list to be passed to new thread or NULL */
85   unsigned int initflag,   /* [in] Initial state of new thread (0 for running or CREATE_SUSPEND for suspended) */
86   unsigned int *thrdaddr)  /* [out] Points to a 32-bit variable that receives the thread identifier */
87 {
88   TRACE("(%p, %d, %p, %p, %d, %p)\n", security, stack_size, start_address, arglist, initflag, thrdaddr);
89
90   /* FIXME */
91   return CreateThread(security, stack_size, (LPTHREAD_START_ROUTINE) start_address,
92                       arglist, initflag, (LPDWORD) thrdaddr);
93 }
94
95 /*********************************************************************
96  *              _endthread (MSVCRT.@)
97  */
98 void _endthread(void)
99 {
100   TRACE("(void)\n");
101
102   /* FIXME */
103   ExitThread(0);
104 }
105
106 /*********************************************************************
107  *              _endthreadex (MSVCRT.@)
108  */
109 void _endthreadex(
110   unsigned int retval) /* [in] Thread exit code */
111 {
112   TRACE("(%d)\n", retval);
113
114   /* FIXME */
115   ExitThread(retval);
116 }
117