Don't return from overlapped ReadFile on EAGAIN and other non-fatal
[wine/gsoc_dplay.git] / dlls / msvcrt / thread.c
blob08139084e48754943b84390d3f4dab8006d5a53c
1 /*
2 * msvcrt.dll thread functions
4 * Copyright 2000 Jon Griffiths
5 */
6 #include "msvcrt.h"
8 #include "msvcrt/malloc.h"
9 #include "msvcrt/process.h"
11 DEFAULT_DEBUG_CHANNEL(msvcrt);
13 /********************************************************************/
15 typedef struct {
16 _beginthread_start_routine_t start_address;
17 void *arglist;
18 } _beginthread_trampoline_t;
20 /*********************************************************************
21 * _beginthread_trampoline
23 static DWORD CALLBACK _beginthread_trampoline(LPVOID arg)
25 _beginthread_trampoline_t local_trampoline;
27 /* Maybe it's just being paranoid, but freeing arg right
28 * away seems safer.
30 memcpy(&local_trampoline,arg,sizeof(local_trampoline));
31 MSVCRT_free(arg);
33 local_trampoline.start_address(local_trampoline.arglist);
34 return 0;
37 /*********************************************************************
38 * _beginthread (MSVCRT.@)
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 */
45 _beginthread_trampoline_t* trampoline;
47 TRACE("(%p, %d, %p)\n", start_address, stack_size, arglist);
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
53 trampoline=MSVCRT_malloc(sizeof(*trampoline));
54 trampoline->start_address = start_address;
55 trampoline->arglist = arglist;
57 /* FIXME */
58 return CreateThread(NULL, stack_size, _beginthread_trampoline, trampoline, 0, NULL);
61 /*********************************************************************
62 * _beginthreadex (MSVCRT.@)
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 */
72 TRACE("(%p, %d, %p, %p, %d, %p)\n", security, stack_size, start_address, arglist, initflag, thrdaddr);
74 /* FIXME */
75 return CreateThread(security, stack_size, (LPTHREAD_START_ROUTINE) start_address,
76 arglist, initflag, (LPDWORD) thrdaddr);
79 /*********************************************************************
80 * _endthread (MSVCRT.@)
82 void _endthread(void)
84 TRACE("(void)\n");
86 /* FIXME */
87 ExitThread(0);
90 /*********************************************************************
91 * _endthreadex (MSVCRT.@)
93 void _endthreadex(
94 unsigned int retval) /* [in] Thread exit code */
96 TRACE("(%d)\n", retval);
98 /* FIXME */
99 ExitThread(retval);