1 | /* $Id: thread.cpp,v 1.5 1999-06-19 17:58:33 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | *
|
---|
5 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
6 | *
|
---|
7 | */
|
---|
8 | /*
|
---|
9 | * Win32 Thread API functions
|
---|
10 | *
|
---|
11 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
12 | *
|
---|
13 | */
|
---|
14 | #include <os2win.h>
|
---|
15 | #include <stdarg.h>
|
---|
16 | #include "thread.h"
|
---|
17 | #include "except.h"
|
---|
18 | #include "misc.h"
|
---|
19 | #include <wprocess.h>
|
---|
20 |
|
---|
21 | static DWORD OPEN32API Win32ThreadProc(LPVOID lpData);
|
---|
22 |
|
---|
23 |
|
---|
24 | //******************************************************************************
|
---|
25 | //******************************************************************************
|
---|
26 | HANDLE WIN32API CreateThread(LPSECURITY_ATTRIBUTES lpsa, DWORD cbStack,
|
---|
27 | LPTHREAD_START_ROUTINE lpStartAddr,
|
---|
28 | LPVOID lpvThreadParm, DWORD fdwCreate,
|
---|
29 | LPDWORD lpIDThread)
|
---|
30 | {
|
---|
31 | Win32Thread *winthread = new Win32Thread(lpStartAddr, lpvThreadParm, fdwCreate);
|
---|
32 |
|
---|
33 | if(winthread == 0)
|
---|
34 | return(0);
|
---|
35 |
|
---|
36 | dprintf(("CreateThread (%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)\n",
|
---|
37 | lpsa,
|
---|
38 | cbStack,
|
---|
39 | lpStartAddr,
|
---|
40 | lpvThreadParm,
|
---|
41 | fdwCreate,
|
---|
42 | lpIDThread));
|
---|
43 |
|
---|
44 | return(O32_CreateThread(lpsa, cbStack, winthread->GetOS2Callback(), (LPVOID)winthread, fdwCreate, lpIDThread));
|
---|
45 | }
|
---|
46 | //******************************************************************************
|
---|
47 | //******************************************************************************
|
---|
48 | DWORD WIN32API GetCurrentThreadId()
|
---|
49 | {
|
---|
50 | dprintf(("GetCurrentThreadId\n"));
|
---|
51 |
|
---|
52 | return(O32_GetCurrentThreadId());
|
---|
53 | }
|
---|
54 | //******************************************************************************
|
---|
55 | //******************************************************************************
|
---|
56 | HANDLE WIN32API GetCurrentThread()
|
---|
57 | {
|
---|
58 | //// dprintf(("GetCurrentThread\n"));
|
---|
59 | return(O32_GetCurrentThread());
|
---|
60 | }
|
---|
61 | //******************************************************************************
|
---|
62 | //******************************************************************************
|
---|
63 | BOOL WIN32API GetExitCodeThread(HANDLE hThread, LPDWORD arg2)
|
---|
64 | {
|
---|
65 | dprintf(("GetExitCodeThread (%08xh,%08xh)\n",
|
---|
66 | hThread,
|
---|
67 | arg2));
|
---|
68 |
|
---|
69 | return O32_GetExitCodeThread(hThread, arg2);
|
---|
70 | }
|
---|
71 | //******************************************************************************
|
---|
72 | //******************************************************************************
|
---|
73 | BOOL WIN32API TerminateThread(HANDLE hThread, DWORD arg2)
|
---|
74 | {
|
---|
75 | dprintf(("TerminateThread (%08xh,%08xh)\n",
|
---|
76 | hThread,
|
---|
77 | arg2));
|
---|
78 |
|
---|
79 | return O32_TerminateThread(hThread, arg2);
|
---|
80 | }
|
---|
81 | //******************************************************************************
|
---|
82 | //******************************************************************************
|
---|
83 | DWORD WIN32API ResumeThread(HANDLE hThread)
|
---|
84 | {
|
---|
85 | dprintf(("ResumeThread (%08xh)\n",
|
---|
86 | hThread));
|
---|
87 |
|
---|
88 | return O32_ResumeThread(hThread);
|
---|
89 | }
|
---|
90 | //******************************************************************************
|
---|
91 | //******************************************************************************
|
---|
92 | INT WIN32API GetThreadPriority(HANDLE hThread)
|
---|
93 | {
|
---|
94 | dprintf(("OS2GetThreadPriority(%08xh)\n",
|
---|
95 | hThread));
|
---|
96 |
|
---|
97 | return O32_GetThreadPriority(hThread);
|
---|
98 | }
|
---|
99 | //******************************************************************************
|
---|
100 | //******************************************************************************
|
---|
101 | DWORD WIN32API SuspendThread(HANDLE hThread)
|
---|
102 | {
|
---|
103 | dprintf(("OS2SuspendThread %08xh)\n",
|
---|
104 | hThread));
|
---|
105 |
|
---|
106 | return O32_SuspendThread(hThread);
|
---|
107 | }
|
---|
108 | //******************************************************************************
|
---|
109 | //******************************************************************************
|
---|
110 | BOOL WIN32API SetThreadPriority(HANDLE hThread, int priority)
|
---|
111 | {
|
---|
112 | dprintf(("OS2SetThreadPriority (%08xh,%08xh)\n",
|
---|
113 | hThread,
|
---|
114 | priority));
|
---|
115 |
|
---|
116 | return O32_SetThreadPriority(hThread, priority);
|
---|
117 | }
|
---|
118 | //******************************************************************************
|
---|
119 | //******************************************************************************
|
---|
120 | VOID WIN32API ExitThread(DWORD exitcode)
|
---|
121 | {
|
---|
122 | dprintf(("ExitThread (%08xu)\n",
|
---|
123 | exitcode));
|
---|
124 |
|
---|
125 | #ifdef WIN32_TIBSEL
|
---|
126 | DestroyTIB();
|
---|
127 | #endif
|
---|
128 | O32_ExitThread(exitcode);
|
---|
129 | }
|
---|
130 | //******************************************************************************
|
---|
131 | //******************************************************************************
|
---|
132 | Win32Thread::Win32Thread(LPTHREAD_START_ROUTINE pUserCallback, LPVOID lpData, DWORD dwFlags)
|
---|
133 | {
|
---|
134 | lpUserData = lpData;
|
---|
135 | pCallback = pUserCallback;
|
---|
136 | this->dwFlags = dwFlags;
|
---|
137 | }
|
---|
138 | //******************************************************************************
|
---|
139 | //******************************************************************************
|
---|
140 | Win32Thread::~Win32Thread()
|
---|
141 | {
|
---|
142 |
|
---|
143 | }
|
---|
144 | //******************************************************************************
|
---|
145 | //******************************************************************************
|
---|
146 | PTHREAD_START_ROUTINE_O32 Win32Thread::GetOS2Callback()
|
---|
147 | {
|
---|
148 | return Win32ThreadProc;
|
---|
149 | }
|
---|
150 | //******************************************************************************
|
---|
151 | //******************************************************************************
|
---|
152 | static DWORD OPEN32API Win32ThreadProc(LPVOID lpData)
|
---|
153 | {
|
---|
154 | Win32Thread *me = (Win32Thread *)lpData;
|
---|
155 | WIN32THREADPROC winthread = me->pCallback;
|
---|
156 | LPVOID userdata = me->lpUserData;
|
---|
157 |
|
---|
158 | delete me; //only called once
|
---|
159 |
|
---|
160 | dprintf(("Win32ThreadProc %d\n", GetCurrentThreadId()));
|
---|
161 |
|
---|
162 | #ifdef WIN32_TIBSEL
|
---|
163 | #else
|
---|
164 | ReplaceExceptionHandler();
|
---|
165 | #endif
|
---|
166 | return(winthread(userdata));
|
---|
167 | }
|
---|
168 | //******************************************************************************
|
---|
169 | //******************************************************************************
|
---|