ReactOS 0.4.15-dev-8109-gd7be748
thread.c
Go to the documentation of this file.
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21#include <precomp.h>
22#include <malloc.h>
23#include <process.h>
24
26typedef unsigned int (__stdcall *_beginthreadex_start_routine_t)(void *);
27
28/********************************************************************/
29
30typedef struct {
33 void *arglist;
35
36/*********************************************************************
37 * _beginthread_trampoline
38 */
40{
41 _beginthread_trampoline_t local_trampoline;
43
44 memcpy(&local_trampoline,arg,sizeof(local_trampoline));
45 data->handle = local_trampoline.thread;
46 free(arg);
47
48 local_trampoline.start_address(local_trampoline.arglist);
49 return 0;
50}
51
52/*********************************************************************
53 * _beginthread (MSVCRT.@)
54 */
56 _beginthread_start_routine_t start_address, /* [in] Start address of routine that begins execution of new thread */
57 unsigned int stack_size, /* [in] Stack size for new thread or 0 */
58 void *arglist) /* [in] Argument list to be passed to new thread or NULL */
59{
60 _beginthread_trampoline_t* trampoline;
62
63 TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
64
65 trampoline = malloc(sizeof(*trampoline));
66 if(!trampoline) {
67 *_errno() = EAGAIN;
68 return -1;
69 }
70
72 trampoline, CREATE_SUSPENDED, NULL);
73 if(!thread) {
74 free(trampoline);
75 *_errno() = EAGAIN;
76 return -1;
77 }
78
79 trampoline->thread = thread;
80 trampoline->start_address = start_address;
81 trampoline->arglist = arglist;
82
83 if(ResumeThread(thread) == -1) {
84 free(trampoline);
85 *_errno() = EAGAIN;
86 return -1;
87 }
88
89 return (uintptr_t)thread;
90}
91
92/*********************************************************************
93 * _endthread (MSVCRT.@)
94 */
95void CDECL _endthread(void)
96{
97 TRACE("(void)\n");
98
99 /* FIXME */
100 ExitThread(0);
101}
#define EAGAIN
Definition: acclib.h:83
static HANDLE thread
Definition: service.c:33
unsigned int uintptr_t
Definition: crtdefs.h:321
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NULL
Definition: types.h:112
#define CDECL
Definition: compat.h:29
#define CALLBACK
Definition: compat.h:35
DWORD WINAPI ResumeThread(IN HANDLE hThread)
Definition: thread.c:567
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:365
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
thread_data_t * msvcrt_get_thread_data(void)
Definition: tls.c:31
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:17
unsigned int(__stdcall * _beginthreadex_start_routine_t)(void *)
Definition: thread.c:26
void CDECL _endthread(void)
Definition: thread.c:95
static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
Definition: thread.c:39
void(* _beginthread_start_routine_t)(void *)
Definition: thread.c:25
uintptr_t _beginthread(_beginthread_start_routine_t start_address, unsigned int stack_size, void *arglist)
Definition: thread.c:55
va_lists_t arglist[FMT_ARGMAX+1]
Definition: format.c:284
#define TRACE(s)
Definition: solgame.cpp:4
_beginthread_start_routine_t start_address
Definition: thread.c:32
#define __stdcall
Definition: typedefs.h:25
#define CREATE_SUSPENDED
Definition: winbase.h:178