Changeset 3205 for trunk/src/wsock32/new/asyncthread.cpp
- Timestamp:
- Mar 23, 2000, 8:21:56 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wsock32/new/asyncthread.cpp
r3198 r3205 1 /* $Id: asyncthread.cpp,v 1. 1 2000-03-22 20:01:04sandervl Exp $ */1 /* $Id: asyncthread.cpp,v 1.2 2000-03-23 19:21:53 sandervl Exp $ */ 2 2 3 3 /* … … 6 6 * Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl) 7 7 * 8 * 9 * Not everything is thread safe 8 * TODO: Not everything is 100% thread safe (i.e. async parameter updates) 10 9 * 11 10 * Project Odin Software License can be found in LICENSE.TXT 11 * 12 12 */ 13 13 #define INCL_BASE 14 14 #include <os2wrap.h> 15 15 #include <os2sel.h> 16 #include <stdlib.h> 16 17 #include <wprocess.h> 17 18 #include <win32api.h> … … 35 36 pThreadParm->asyncProc((PVOID)arg); 36 37 37 WSASetBlocking(TRUE, pThreadParm->hThread); 38 //only for blocking hooks (currently not implemented 39 //// if(pThreadParm->request == ASYNC_BLOCKHOOK) 40 //// WSASetBlocking(FALSE, pThreadParm->hThread); 41 42 pThreadParm->fActive = FALSE; 43 RemoveFromQueue(pThreadParm); 44 free((PVOID)pThreadParm); 38 45 39 46 DosExit(EXIT_THREAD, 0); … … 41 48 //****************************************************************************** 42 49 //****************************************************************************** 43 ULONG QueueAsyncJob(ASYNCTHREADPROC asyncproc, PASYNCTHREADPARM pThreadParm )50 ULONG QueueAsyncJob(ASYNCTHREADPROC asyncproc, PASYNCTHREADPARM pThreadParm, BOOL fSetBlocking) 44 51 { 45 52 APIRET rc; … … 55 62 AddToQueue(pThreadParm); 56 63 57 WSASetBlocking(TRUE);64 if(fSetBlocking) WSASetBlocking(TRUE); 58 65 59 66 rc = DosCreateThread(&tid, AsyncThread, (ULONG)pThreadParm, CREATE_READY, 16384); … … 61 68 { 62 69 dprintf(("QueueAsyncJob: DosCreateThread failed with error %x", rc)); 63 WSASetBlocking(FALSE);70 if(fSetBlocking) WSASetBlocking(FALSE); 64 71 RemoveFromQueue(pThreadParm); 65 72 WSASetLastError(WSAEFAULT); … … 83 90 void RemoveFromQueue(PASYNCTHREADPARM pThreadParm) 84 91 { 85 PASYNCTHREADPARM p arm;86 87 asyncThreadMutex.enter(); 88 p arm= threadList;89 90 if(p arm== pThreadParm) {92 PASYNCTHREADPARM pThreadInfo; 93 94 asyncThreadMutex.enter(); 95 pThreadInfo = threadList; 96 97 if(pThreadInfo == pThreadParm) { 91 98 threadList = pThreadParm->next; 92 99 } 93 100 else { 94 while(p arm->next) {95 if(p arm->next == pThreadParm) {96 p arm->next = pThreadParm->next;101 while(pThreadInfo->next) { 102 if(pThreadInfo->next == pThreadParm) { 103 pThreadInfo->next = pThreadParm->next; 97 104 break; 98 105 } 99 p arm = parm->next;100 } 101 if(p arm== NULL) {106 pThreadInfo = pThreadInfo->next; 107 } 108 if(pThreadInfo == NULL) { 102 109 dprintf(("RemoveFromQueue: parm %x not found!!", pThreadParm)); 103 110 DebugInt3(); … … 111 118 int WIN32API WSACancelAsyncRequest(LHANDLE hAsyncTaskHandle) 112 119 { 113 PASYNCTHREADPARM p arm;120 PASYNCTHREADPARM pThreadInfo; 114 121 BOOL found = FALSE; 115 122 116 123 dprintf(("WSACancelAsyncRequest: cancel task %x", hAsyncTaskHandle)); 117 124 asyncThreadMutex.enter(); 118 p arm= threadList;119 120 while(p arm) {121 if(p arm->hAsyncTaskHandle == hAsyncTaskHandle) {122 p arm->fCancelled = TRUE;125 pThreadInfo = threadList; 126 127 while(pThreadInfo) { 128 if(pThreadInfo->hAsyncTaskHandle == hAsyncTaskHandle) { 129 pThreadInfo->fCancelled = TRUE; 123 130 found = TRUE; 124 131 break; 125 132 } 126 p arm = parm->next;133 pThreadInfo = pThreadInfo->next; 127 134 } 128 135 asyncThreadMutex.leave(); … … 134 141 } 135 142 //****************************************************************************** 143 //Only to cancel blocking hooks 144 //****************************************************************************** 145 int WIN32API WSACancelBlockingCall() 146 { 147 HANDLE hThread = GetCurrentThread(); 148 149 dprintf(("WSACancelBlockingCall")); 150 #if 0 151 asyncThreadMutex.enter(); 152 pThreadInfo = threadList; 153 154 while(pThreadInfo) { 155 if(pThreadInfo->hThread == hThread) { 156 pThreadInfo->fCancelled = TRUE; 157 158 if(pThreadInfo->request == ASYNC_BLOCKHOOK) { 159 ret = so_cancel(pThreadInfo->blockedsocket); 160 } 161 162 found = TRUE; 163 break; 164 } 165 pThreadInfo = pThreadInfo->next; 166 } 167 asyncThreadMutex.leave(); 168 #endif 169 return SOCKET_ERROR; 170 } 171 //****************************************************************************** 172 //Assumes caller owns async thread mutex! 173 //****************************************************************************** 174 static PASYNCTHREADPARM FindAsyncEvent(SOCKET s) 175 { 176 PASYNCTHREADPARM pThreadInfo; 177 178 pThreadInfo = threadList; 179 while(pThreadInfo) { 180 if(pThreadInfo->u.asyncselect.s == s) { 181 return pThreadInfo; 182 } 183 pThreadInfo = pThreadInfo->next; 184 } 185 return NULL; 186 } 187 //****************************************************************************** 188 //****************************************************************************** 189 BOOL FindAndSetAsyncEvent(SOCKET s, HWND hwnd, int msg, ULONG lEvent) 190 { 191 PASYNCTHREADPARM pThreadInfo; 192 193 asyncThreadMutex.enter(); 194 pThreadInfo = FindAsyncEvent(s); 195 if(pThreadInfo) { 196 pThreadInfo->u.asyncselect.lEvents = lEvent; 197 pThreadInfo->hwnd = hwnd; 198 pThreadInfo->msg = msg; 199 //cancel pending select in async select thread (if any) 200 so_cancel(s); 201 202 //unblock async thread if it was waiting 203 pThreadInfo->u.asyncselect.asyncSem->post(); 204 } 205 asyncThreadMutex.leave(); 206 return(pThreadInfo != NULL); 207 } 208 //****************************************************************************** 136 209 //****************************************************************************** 137 210 void EnableAsyncEvent(SOCKET s, ULONG flags) 138 211 { 212 PASYNCTHREADPARM pThreadInfo; 213 214 asyncThreadMutex.enter(); 215 pThreadInfo = FindAsyncEvent(s); 216 if(pThreadInfo) { 217 pThreadInfo->u.asyncselect.lEventsPending |= (pThreadInfo->u.asyncselect.lEvents & flags); 218 //cancel pending select in async select thread (if any) 219 so_cancel(s); 220 221 //unblock async thread if it was waiting 222 pThreadInfo->u.asyncselect.asyncSem->post(); 223 } 224 asyncThreadMutex.leave(); 139 225 } 140 226 //****************************************************************************** … … 142 228 BOOL QueryAsyncEvent(SOCKET s, HWND *pHwnd, int *pMsg, ULONG *plEvent) 143 229 { 144 return FALSE; 145 } 146 //****************************************************************************** 147 //****************************************************************************** 230 PASYNCTHREADPARM pThreadInfo; 231 232 asyncThreadMutex.enter(); 233 pThreadInfo = FindAsyncEvent(s); 234 if(pThreadInfo) { 235 *pHwnd = pThreadInfo->hwnd; 236 *pMsg = pThreadInfo->msg; 237 *plEvent = pThreadInfo->u.asyncselect.lEvents; 238 } 239 asyncThreadMutex.leave(); 240 return(pThreadInfo != NULL); 241 } 242 //****************************************************************************** 243 //******************************************************************************
Note:
See TracChangeset
for help on using the changeset viewer.