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