Fixed some alignment issues (based on a patch by Gregg Mattinson).
[wine.git] / dlls / msvcrt / thread.c
blob586561c11c28fe827a4cebdd1701bf112a127172
1 /*
2 * msvcrt.dll thread functions
4 * Copyright 2000 Jon Griffiths
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.
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.
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
20 #include "msvcrt.h"
22 #include "msvcrt/malloc.h"
23 #include "msvcrt/process.h"
25 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt);
29 /********************************************************************/
31 typedef struct {
32 _beginthread_start_routine_t start_address;
33 void *arglist;
34 } _beginthread_trampoline_t;
36 /*********************************************************************
37 * _beginthread_trampoline
39 static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
41 _beginthread_trampoline_t local_trampoline;
43 /* Maybe it's just being paranoid, but freeing arg right
44 * away seems safer.
46 memcpy(&local_trampoline,arg,sizeof(local_trampoline));
47 MSVCRT_free(arg);
49 local_trampoline.start_address(local_trampoline.arglist);
50 return 0;
53 /*********************************************************************
54 * _beginthread (MSVCRT.@)
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 */
61 _beginthread_trampoline_t* trampoline;
63 TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
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
69 trampoline=MSVCRT_malloc(sizeof(*trampoline));
70 trampoline->start_address = start_address;
71 trampoline->arglist = arglist;
73 /* FIXME */
74 return CreateThread(NULL, stack_size, _beginthread_trampoline, trampoline, 0, NULL);
77 /*********************************************************************
78 * _beginthreadex (MSVCRT.@)
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 */
88 TRACE("(%p, %d, %p, %p, %d, %p)\n", security, stack_size, start_address, arglist, initflag, thrdaddr);
90 /* FIXME */
91 return CreateThread(security, stack_size, (LPTHREAD_START_ROUTINE) start_address,
92 arglist, initflag, (LPDWORD) thrdaddr);
95 /*********************************************************************
96 * _endthread (MSVCRT.@)
98 void _endthread(void)
100 TRACE("(void)\n");
102 /* FIXME */
103 ExitThread(0);
106 /*********************************************************************
107 * _endthreadex (MSVCRT.@)
109 void _endthreadex(
110 unsigned int retval) /* [in] Thread exit code */
112 TRACE("(%d)\n", retval);
114 /* FIXME */
115 ExitThread(retval);