source: trunk/src/kernel32/thread.cpp@ 529

Last change on this file since 529 was 529, checked in by phaller, 26 years ago

Fix: removed ODINCRT remains

File size: 6.6 KB
Line 
1/* $Id: thread.cpp,v 1.9 1999-08-17 16:35:10 phaller Exp $ */
2
3/*
4 * Win32 Thread API functions
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#include <os2win.h>
13#include <stdarg.h>
14//#include <odincrt.h>
15#include "thread.h"
16#include "except.h"
17#include <misc.h>
18#include <wprocess.h>
19#include <windll.h>
20#include <winexe.h>
21
22static DWORD OPEN32API Win32ThreadProc(LPVOID lpData);
23
24
25//******************************************************************************
26//******************************************************************************
27HANDLE WIN32API CreateThread(LPSECURITY_ATTRIBUTES lpsa, DWORD cbStack,
28 LPTHREAD_START_ROUTINE lpStartAddr,
29 LPVOID lpvThreadParm, DWORD fdwCreate,
30 LPDWORD lpIDThread)
31{
32 Win32Thread *winthread;
33
34 winthread = new Win32Thread(lpStartAddr, lpvThreadParm, fdwCreate);
35
36 if(winthread == 0)
37 return(0);
38
39 dprintf(("CreateThread (%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)\n",
40 lpsa,
41 cbStack,
42 lpStartAddr,
43 lpvThreadParm,
44 fdwCreate,
45 lpIDThread));
46
47 return(O32_CreateThread(lpsa, cbStack, winthread->GetOS2Callback(), (LPVOID)winthread, fdwCreate, lpIDThread));
48}
49//******************************************************************************
50//******************************************************************************
51DWORD WIN32API GetCurrentThreadId()
52{
53//// dprintf(("GetCurrentThreadId\n"));
54 return(O32_GetCurrentThreadId());
55}
56//******************************************************************************
57//******************************************************************************
58HANDLE WIN32API GetCurrentThread()
59{
60//// dprintf(("GetCurrentThread\n"));
61 return(O32_GetCurrentThread());
62}
63//******************************************************************************
64//******************************************************************************
65BOOL WIN32API GetExitCodeThread(HANDLE hThread, LPDWORD arg2)
66{
67 dprintf(("GetExitCodeThread (%08xh,%08xh)\n",
68 hThread,
69 arg2));
70
71 return O32_GetExitCodeThread(hThread, arg2);
72}
73//******************************************************************************
74//******************************************************************************
75BOOL WIN32API TerminateThread(HANDLE hThread, DWORD arg2)
76{
77 dprintf(("TerminateThread (%08xh,%08xh)\n",
78 hThread,
79 arg2));
80
81 return O32_TerminateThread(hThread, arg2);
82}
83//******************************************************************************
84//******************************************************************************
85DWORD WIN32API ResumeThread(HANDLE hThread)
86{
87 dprintf(("ResumeThread (%08xh)\n",
88 hThread));
89
90 return O32_ResumeThread(hThread);
91}
92//******************************************************************************
93//******************************************************************************
94INT WIN32API GetThreadPriority(HANDLE hThread)
95{
96 dprintf(("OS2GetThreadPriority(%08xh)\n",
97 hThread));
98
99 return O32_GetThreadPriority(hThread);
100}
101//******************************************************************************
102//******************************************************************************
103DWORD WIN32API SuspendThread(HANDLE hThread)
104{
105 dprintf(("OS2SuspendThread %08xh)\n",
106 hThread));
107
108 return O32_SuspendThread(hThread);
109}
110//******************************************************************************
111//******************************************************************************
112BOOL WIN32API SetThreadPriority(HANDLE hThread, int priority)
113{
114 dprintf(("OS2SetThreadPriority (%08xh,%08xh)\n",
115 hThread,
116 priority));
117
118 return O32_SetThreadPriority(hThread, priority);
119}
120//******************************************************************************
121//******************************************************************************
122VOID WIN32API ExitThread(DWORD exitcode)
123{
124 dprintf(("ExitThread (%08xu)\n",
125 exitcode));
126
127 Win32Dll::detachThreadFromAllDlls(); //send DLL_THREAD_DETACH message to all dlls
128 Win32Dll::tlsDetachThreadFromAllDlls(); //destroy TLS structures of all dlls
129 WinExe->tlsDetachThread(); //destroy TLS structure of main exe
130 DestroyTIB();
131 O32_ExitThread(exitcode);
132}
133//******************************************************************************
134//******************************************************************************
135Win32Thread::Win32Thread(LPTHREAD_START_ROUTINE pUserCallback, LPVOID lpData, DWORD dwFlags)
136{
137 lpUserData = lpData;
138 pCallback = pUserCallback;
139 this->dwFlags = dwFlags;
140}
141//******************************************************************************
142//******************************************************************************
143Win32Thread::~Win32Thread()
144{
145
146}
147//******************************************************************************
148//******************************************************************************
149PTHREAD_START_ROUTINE_O32 Win32Thread::GetOS2Callback()
150{
151 return Win32ThreadProc;
152}
153//******************************************************************************
154//******************************************************************************
155static DWORD OPEN32API Win32ThreadProc(LPVOID lpData)
156{
157 Win32Thread *me = (Win32Thread *)lpData;
158 WIN32THREADPROC winthread = me->pCallback;
159 LPVOID userdata = me->lpUserData;
160 DWORD rc;
161
162 delete(me); //only called once
163
164 dprintf(("Win32ThreadProc %d\n", GetCurrentThreadId()));
165
166 TEB *winteb = (TEB *)InitializeTIB();
167 if(winteb == NULL) {
168 dprintf(("Win32ThreadProc: InitializeTIB failed!!"));
169 DebugInt3();
170 return 0;
171 }
172 winteb->flags = me->dwFlags;
173
174 THDB *thdb = (THDB *)(winteb+1);
175 thdb->entry_point = (void *)winthread;
176 thdb->entry_arg = (void *)userdata;
177
178 SetWin32TIB();
179 WinExe->tlsAttachThread(); //setup TLS structure of main exe
180 Win32Dll::tlsAttachThreadToAllDlls(); //setup TLS structures of all dlls
181 Win32Dll::attachThreadToAllDlls(); //send DLL_THREAD_ATTACH message to all dlls
182
183 rc = winthread(userdata);
184
185 Win32Dll::detachThreadFromAllDlls(); //send DLL_THREAD_DETACH message to all dlls
186 Win32Dll::tlsDetachThreadFromAllDlls(); //destroy TLS structures of all dlls
187 WinExe->tlsDetachThread(); //destroy TLS structure of main exe
188 DestroyTIB();
189 return rc;
190}
191//******************************************************************************
192//******************************************************************************
Note: See TracBrowser for help on using the repository browser.