summaryrefslogtreecommitdiff
path: root/rts/win32/IOManager.c
diff options
context:
space:
mode:
Diffstat (limited to 'rts/win32/IOManager.c')
-rw-r--r--rts/win32/IOManager.c60
1 files changed, 30 insertions, 30 deletions
diff --git a/rts/win32/IOManager.c b/rts/win32/IOManager.c
index f155180ef3..e5da32b982 100644
--- a/rts/win32/IOManager.c
+++ b/rts/win32/IOManager.c
@@ -22,7 +22,7 @@
* Internal state maintained by the IO manager.
*/
typedef struct IOManagerState {
- CritSection manLock;
+ Mutex manLock;
WorkQueue* workQueue;
int queueSize;
int numWorkers;
@@ -30,7 +30,7 @@ typedef struct IOManagerState {
HANDLE hExitEvent;
unsigned int requestID;
/* fields for keeping track of active WorkItems */
- CritSection active_work_lock;
+ Mutex active_work_lock;
WorkItem* active_work_items;
UINT sleepResolution;
} IOManagerState;
@@ -65,7 +65,7 @@ IOWorkerProc(PVOID param)
// The error code is communicated back on completion of request; reset.
errCode = 0;
- EnterCriticalSection(&iom->manLock);
+ OS_ACQUIRE_LOCK(&iom->manLock);
/* Signal that the worker is idle.
*
* 'workersIdle' is used when determining whether or not to
@@ -73,7 +73,7 @@ IOWorkerProc(PVOID param)
* (see addIORequest().)
*/
iom->workersIdle++;
- LeaveCriticalSection(&iom->manLock);
+ OS_RELEASE_LOCK(&iom->manLock);
/*
* A possible future refinement is to make long-term idle threads
@@ -85,19 +85,19 @@ IOWorkerProc(PVOID param)
if (rc == WAIT_OBJECT_0) {
// we received the exit event
- EnterCriticalSection(&iom->manLock);
+ OS_ACQUIRE_LOCK(&iom->manLock);
ioMan->numWorkers--;
- LeaveCriticalSection(&iom->manLock);
+ OS_RELEASE_LOCK(&iom->manLock);
return 0;
}
- EnterCriticalSection(&iom->manLock);
+ OS_ACQUIRE_LOCK(&iom->manLock);
/* Signal that the thread is 'non-idle' and about to consume
* a work item.
*/
iom->workersIdle--;
iom->queueSize--;
- LeaveCriticalSection(&iom->manLock);
+ OS_RELEASE_LOCK(&iom->manLock);
if ( rc == (WAIT_OBJECT_0 + 1) ) {
/* work item available, fetch it. */
@@ -266,17 +266,17 @@ IOWorkerProc(PVOID param)
} else {
fprintf(stderr, "unable to fetch work; fatal.\n");
fflush(stderr);
- EnterCriticalSection(&iom->manLock);
+ OS_ACQUIRE_LOCK(&iom->manLock);
ioMan->numWorkers--;
- LeaveCriticalSection(&iom->manLock);
+ OS_RELEASE_LOCK(&iom->manLock);
return 1;
}
} else {
fprintf(stderr, "waiting failed (%lu); fatal.\n", rc);
fflush(stderr);
- EnterCriticalSection(&iom->manLock);
+ OS_ACQUIRE_LOCK(&iom->manLock);
ioMan->numWorkers--;
- LeaveCriticalSection(&iom->manLock);
+ OS_RELEASE_LOCK(&iom->manLock);
return 1;
}
}
@@ -334,13 +334,13 @@ StartIOManager(void)
}
ioMan->hExitEvent = hExit;
- InitializeCriticalSection(&ioMan->manLock);
+ OS_INIT_LOCK(&ioMan->manLock);
ioMan->workQueue = wq;
ioMan->numWorkers = 0;
ioMan->workersIdle = 0;
ioMan->queueSize = 0;
ioMan->requestID = 1;
- InitializeCriticalSection(&ioMan->active_work_lock);
+ OS_INIT_LOCK(&ioMan->active_work_lock);
ioMan->active_work_items = NULL;
ioMan->sleepResolution = sleepResolution;
@@ -360,7 +360,7 @@ int
depositWorkItem( unsigned int reqID,
WorkItem* wItem )
{
- EnterCriticalSection(&ioMan->manLock);
+ OS_ACQUIRE_LOCK(&ioMan->manLock);
#if 0
fprintf(stderr, "depositWorkItem: %d/%d\n",
@@ -397,9 +397,9 @@ depositWorkItem( unsigned int reqID,
if ( (ioMan->workersIdle < ioMan->queueSize) ) {
/* see if giving up our quantum ferrets out some idle threads.
*/
- LeaveCriticalSection(&ioMan->manLock);
+ OS_RELEASE_LOCK(&ioMan->manLock);
Sleep(0);
- EnterCriticalSection(&ioMan->manLock);
+ OS_ACQUIRE_LOCK(&ioMan->manLock);
if ( (ioMan->workersIdle < ioMan->queueSize) ) {
/* No, go ahead and create another. */
ioMan->numWorkers++;
@@ -408,7 +408,7 @@ depositWorkItem( unsigned int reqID,
}
}
}
- LeaveCriticalSection(&ioMan->manLock);
+ OS_RELEASE_LOCK(&ioMan->manLock);
if (SubmitWork(ioMan->workQueue,wItem)) {
/* Note: the work item has potentially been consumed by a worker thread
@@ -522,17 +522,17 @@ void ShutdownIOManager ( bool wait_threads )
if (wait_threads) {
/* Wait for all worker threads to die. */
for (;;) {
- EnterCriticalSection(&ioMan->manLock);
+ OS_ACQUIRE_LOCK(&ioMan->manLock);
num = ioMan->numWorkers;
- LeaveCriticalSection(&ioMan->manLock);
+ OS_RELEASE_LOCK(&ioMan->manLock);
if (num == 0)
break;
Sleep(10);
}
FreeWorkQueue(ioMan->workQueue);
CloseHandle(ioMan->hExitEvent);
- DeleteCriticalSection(&ioMan->active_work_lock);
- DeleteCriticalSection(&ioMan->manLock);
+ OS_CLOSE_LOCK(&ioMan->active_work_lock);
+ OS_CLOSE_LOCK(&ioMan->manLock);
mmresult = timeEndPeriod(ioMan->sleepResolution);
if (mmresult != MMSYSERR_NOERROR) {
@@ -550,10 +550,10 @@ void
RegisterWorkItem(IOManagerState* ioMan,
WorkItem* wi)
{
- EnterCriticalSection(&ioMan->active_work_lock);
+ OS_ACQUIRE_LOCK(&ioMan->active_work_lock);
wi->link = ioMan->active_work_items;
ioMan->active_work_items = wi;
- LeaveCriticalSection(&ioMan->active_work_lock);
+ OS_RELEASE_LOCK(&ioMan->active_work_lock);
}
static
@@ -563,7 +563,7 @@ DeregisterWorkItem(IOManagerState* ioMan,
{
WorkItem *ptr, *prev;
- EnterCriticalSection(&ioMan->active_work_lock);
+ OS_ACQUIRE_LOCK(&ioMan->active_work_lock);
for(prev=NULL,ptr=ioMan->active_work_items;ptr;prev=ptr,ptr=ptr->link) {
if (wi->requestID == ptr->requestID) {
if (prev==NULL) {
@@ -571,13 +571,13 @@ DeregisterWorkItem(IOManagerState* ioMan,
} else {
prev->link = ptr->link;
}
- LeaveCriticalSection(&ioMan->active_work_lock);
+ OS_RELEASE_LOCK(&ioMan->active_work_lock);
return;
}
}
fprintf(stderr, "DeregisterWorkItem: unable to locate work item %d\n",
wi->requestID);
- LeaveCriticalSection(&ioMan->active_work_lock);
+ OS_RELEASE_LOCK(&ioMan->active_work_lock);
}
@@ -596,11 +596,11 @@ void
abandonWorkRequest ( int reqID )
{
WorkItem *ptr;
- EnterCriticalSection(&ioMan->active_work_lock);
+ OS_ACQUIRE_LOCK(&ioMan->active_work_lock);
for(ptr=ioMan->active_work_items;ptr;ptr=ptr->link) {
if (ptr->requestID == (unsigned int)reqID ) {
ptr->abandonOp = 1;
- LeaveCriticalSection(&ioMan->active_work_lock);
+ OS_RELEASE_LOCK(&ioMan->active_work_lock);
return;
}
}
@@ -608,7 +608,7 @@ abandonWorkRequest ( int reqID )
* finished sometime since awaitRequests() last drained the completed
* request table; i.e., not an error.
*/
- LeaveCriticalSection(&ioMan->active_work_lock);
+ OS_RELEASE_LOCK(&ioMan->active_work_lock);
}
#endif