1 | /* $Id: thread.cpp,v 1.2 1999-05-31 19:22:44 phaller 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 |
|
---|
19 | static DWORD OPEN32API Win32ThreadProc(LPVOID lpData);
|
---|
20 |
|
---|
21 |
|
---|
22 | //******************************************************************************
|
---|
23 | //******************************************************************************
|
---|
24 | HANDLE WIN32API CreateThread(LPSECURITY_ATTRIBUTES lpsa, DWORD cbStack,
|
---|
25 | LPTHREAD_START_ROUTINE lpStartAddr,
|
---|
26 | LPVOID lpvThreadParm, DWORD fdwCreate,
|
---|
27 | LPDWORD lpIDThread)
|
---|
28 | {
|
---|
29 | Win32Thread *winthread = new Win32Thread(lpStartAddr, lpvThreadParm);
|
---|
30 |
|
---|
31 | if(winthread == 0)
|
---|
32 | return(0);
|
---|
33 |
|
---|
34 | dprintf(("CreateThread (%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)\n",
|
---|
35 | lpsa,
|
---|
36 | cbStack,
|
---|
37 | lpStartAddr,
|
---|
38 | lpvThreadParm,
|
---|
39 | fdwCreate,
|
---|
40 | lpIDThread));
|
---|
41 |
|
---|
42 | return(O32_CreateThread(lpsa, cbStack, winthread->GetOS2Callback(), (LPVOID)winthread, fdwCreate, lpIDThread));
|
---|
43 | }
|
---|
44 | //******************************************************************************
|
---|
45 | //******************************************************************************
|
---|
46 | DWORD WIN32API GetCurrentThreadId()
|
---|
47 | {
|
---|
48 | dprintf(("GetCurrentThreadId\n"));
|
---|
49 |
|
---|
50 | return(O32_GetCurrentThreadId());
|
---|
51 | }
|
---|
52 | //******************************************************************************
|
---|
53 | //******************************************************************************
|
---|
54 | HANDLE WIN32API GetCurrentThread()
|
---|
55 | {
|
---|
56 | //// dprintf(("GetCurrentThread\n"));
|
---|
57 | return(O32_GetCurrentThread());
|
---|
58 | }
|
---|
59 | //******************************************************************************
|
---|
60 | //******************************************************************************
|
---|
61 | BOOL WIN32API GetExitCodeThread(HANDLE hThread, LPDWORD arg2)
|
---|
62 | {
|
---|
63 | dprintf(("GetExitCodeThread (%08xh,%08xh)\n",
|
---|
64 | hThread,
|
---|
65 | arg2));
|
---|
66 |
|
---|
67 | return O32_GetExitCodeThread(hThread, arg2);
|
---|
68 | }
|
---|
69 | //******************************************************************************
|
---|
70 | //******************************************************************************
|
---|
71 | BOOL WIN32API TerminateThread(HANDLE hThread, DWORD arg2)
|
---|
72 | {
|
---|
73 | dprintf(("TerminateThread (%08xh,%08xh)\n",
|
---|
74 | hThread,
|
---|
75 | arg2));
|
---|
76 |
|
---|
77 | return O32_TerminateThread(hThread, arg2);
|
---|
78 | }
|
---|
79 | //******************************************************************************
|
---|
80 | //******************************************************************************
|
---|
81 | DWORD WIN32API ResumeThread(HANDLE hThread)
|
---|
82 | {
|
---|
83 | dprintf(("ResumeThread (%08xh)\n",
|
---|
84 | hThread));
|
---|
85 |
|
---|
86 | return O32_ResumeThread(hThread);
|
---|
87 | }
|
---|
88 | //******************************************************************************
|
---|
89 | //******************************************************************************
|
---|
90 | INT WIN32API GetThreadPriority(HANDLE hThread)
|
---|
91 | {
|
---|
92 | dprintf(("OS2GetThreadPriority(%08xh)\n",
|
---|
93 | hThread));
|
---|
94 |
|
---|
95 | return O32_GetThreadPriority(hThread);
|
---|
96 | }
|
---|
97 | //******************************************************************************
|
---|
98 | //******************************************************************************
|
---|
99 | DWORD WIN32API SuspendThread(HANDLE hThread)
|
---|
100 | {
|
---|
101 | dprintf(("OS2SuspendThread %08xh)\n",
|
---|
102 | hThread));
|
---|
103 |
|
---|
104 | return O32_SuspendThread(hThread);
|
---|
105 | }
|
---|
106 | //******************************************************************************
|
---|
107 | //******************************************************************************
|
---|
108 | BOOL WIN32API SetThreadPriority(HANDLE hThread, int priority)
|
---|
109 | {
|
---|
110 | dprintf(("OS2SetThreadPriority (%08xh,%08xh)\n",
|
---|
111 | hThread
|
---|
112 | priority));
|
---|
113 |
|
---|
114 | return O32_SetThreadPriority(hThread, priority);
|
---|
115 | }
|
---|
116 | //******************************************************************************
|
---|
117 | //******************************************************************************
|
---|
118 | VOID WIN32API ExitThread(DWORD exitcode)
|
---|
119 | {
|
---|
120 | dprintf(("ExitThread (%08xu)\n",
|
---|
121 | exitcode));
|
---|
122 |
|
---|
123 | O32_ExitThread(exitcode);
|
---|
124 | }
|
---|
125 | //******************************************************************************
|
---|
126 | //******************************************************************************
|
---|
127 | Win32Thread::Win32Thread(LPTHREAD_START_ROUTINE pUserCallback, LPVOID lpData)
|
---|
128 | {
|
---|
129 | lpUserData = lpData;
|
---|
130 | pCallback = pUserCallback;
|
---|
131 | }
|
---|
132 | //******************************************************************************
|
---|
133 | //******************************************************************************
|
---|
134 | Win32Thread::~Win32Thread()
|
---|
135 | {
|
---|
136 |
|
---|
137 | }
|
---|
138 | //******************************************************************************
|
---|
139 | //******************************************************************************
|
---|
140 | PTHREAD_START_ROUTINE_O32 Win32Thread::GetOS2Callback()
|
---|
141 | {
|
---|
142 | return Win32ThreadProc;
|
---|
143 | }
|
---|
144 | //******************************************************************************
|
---|
145 | //******************************************************************************
|
---|
146 | static DWORD OPEN32API Win32ThreadProc(LPVOID lpData)
|
---|
147 | {
|
---|
148 | Win32Thread *me = (Win32Thread *)lpData;
|
---|
149 | WIN32THREADPROC winthread = me->pCallback;
|
---|
150 | LPVOID userdata = me->lpUserData;
|
---|
151 |
|
---|
152 | delete me; //only called once
|
---|
153 |
|
---|
154 | dprintf(("Win32ThreadProc %d\n",
|
---|
155 | GetCurrentThreadId()));
|
---|
156 |
|
---|
157 | ReplaceExceptionHandler();
|
---|
158 | return(winthread(userdata));
|
---|
159 | }
|
---|
160 | //******************************************************************************
|
---|
161 | //******************************************************************************
|
---|