*
* (c) sof, 2002-2003.
*/
+
+#if !defined(THREADED_RTS)
+
#include "Rts.h"
#include "IOManager.h"
#include "WorkQueue.h"
*
* Note: Sleep() is in milliseconds, not micros.
*/
- Sleep(work->workData.delayData.msecs / 1000);
+ Sleep((work->workData.delayData.msecs + 999) / 1000);
len = work->workData.delayData.msecs;
complData = NULL;
fd = 0;
free(work);
} else {
fprintf(stderr, "unable to fetch work; fatal.\n"); fflush(stderr);
+ EnterCriticalSection(&iom->manLock);
+ ioMan->numWorkers--;
+ LeaveCriticalSection(&iom->manLock);
return 1;
}
} else {
fprintf(stderr, "waiting failed (%lu); fatal.\n", rc); fflush(stderr);
+ EnterCriticalSection(&iom->manLock);
+ ioMan->numWorkers--;
+ LeaveCriticalSection(&iom->manLock);
return 1;
}
}
if ( (ioMan->workersIdle < ioMan->queueSize) ) {
/* No, go ahead and create another. */
ioMan->numWorkers++;
- LeaveCriticalSection(&ioMan->manLock);
- NewIOWorkerThread(ioMan);
- } else {
- LeaveCriticalSection(&ioMan->manLock);
+ if (!NewIOWorkerThread(ioMan)) {
+ ioMan->numWorkers--;
+ }
}
- } else {
- LeaveCriticalSection(&ioMan->manLock);
}
+ LeaveCriticalSection(&ioMan->manLock);
if (SubmitWork(ioMan->workQueue,wItem)) {
/* Note: the work item has potentially been consumed by a worker thread
return depositWorkItem(reqID, wItem);
}
-void ShutdownIOManager ( void )
+void ShutdownIOManager ( rtsBool wait_threads )
{
int num;
SetEvent(ioMan->hExitEvent);
- /* Wait for all worker threads to die. */
- for (;;) {
- EnterCriticalSection(&ioMan->manLock);
- num = ioMan->numWorkers;
- LeaveCriticalSection(&ioMan->manLock);
- if (num == 0)
- break;
- Sleep(10);
+ if (wait_threads) {
+ /* Wait for all worker threads to die. */
+ for (;;) {
+ EnterCriticalSection(&ioMan->manLock);
+ num = ioMan->numWorkers;
+ LeaveCriticalSection(&ioMan->manLock);
+ if (num == 0)
+ break;
+ Sleep(10);
+ }
+ FreeWorkQueue(ioMan->workQueue);
+ CloseHandle(ioMan->hExitEvent);
+ DeleteCriticalSection(&ioMan->active_work_lock);
+ DeleteCriticalSection(&ioMan->manLock);
+ free(ioMan);
+ ioMan = NULL;
}
- FreeWorkQueue(ioMan->workQueue);
- CloseHandle(ioMan->hExitEvent);
- free(ioMan);
- ioMan = NULL;
}
/* Keep track of WorkItems currently being serviced. */
*/
LeaveCriticalSection(&ioMan->active_work_lock);
}
+
+#endif