char* buffer,
CompletionProc onCompletion)
{
- WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem));
+ WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem));
+ unsigned int reqID = ioMan->requestID++;
if (!ioMan || !wItem) return 0;
/* Fill in the blanks */
wItem->workData.ioData.buf = buffer;
wItem->onCompletion = onCompletion;
- wItem->requestID = ioMan->requestID++;
+ wItem->requestID = reqID;
EnterCriticalSection(&ioMan->manLock);
/* If there are no worker threads available, create one.
}
if (SubmitWork(ioMan->workQueue,wItem)) {
- return wItem->requestID;
+ /* Note: the work item has potentially been consumed by a worker thread
+ * (and freed) at this point, so we cannot use wItem's requestID.
+ */
+ return reqID;
} else {
- return 0;
+ return 0;
}
}
CompletionProc onCompletion)
{
WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem));
+ unsigned int reqID = ioMan->requestID++;
if (!ioMan || !wItem) return FALSE;
/* Fill in the blanks */
wItem->workKind = WORKER_DELAY;
wItem->workData.delayData.msecs = msecs;
wItem->onCompletion = onCompletion;
- wItem->requestID = ioMan->requestID++;
+ wItem->requestID = reqID;
EnterCriticalSection(&ioMan->manLock);
#if 0
}
if (SubmitWork(ioMan->workQueue,wItem)) {
- return wItem->requestID;
+ /* See AddIORequest() comment */
+ return reqID;
} else {
- return 0;
+ return 0;
}
}
CompletionProc onCompletion)
{
WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem));
+ unsigned int reqID = ioMan->requestID++;
if (!ioMan || !wItem) return FALSE;
/* Fill in the blanks */
wItem->workData.procData.proc = proc;
wItem->workData.procData.param = param;
wItem->onCompletion = onCompletion;
- wItem->requestID = ioMan->requestID++;
+ wItem->requestID = reqID;
EnterCriticalSection(&ioMan->manLock);
#if 0
}
if (SubmitWork(ioMan->workQueue,wItem)) {
- return wItem->requestID;
+ /* See AddIORequest() comment */
+ return reqID;
} else {
- return 0;
+ return 0;
}
}