Changeset 39545 in vbox for trunk/src/VBox/Runtime/common/misc/reqpool.cpp
- Timestamp:
- Dec 7, 2011 10:27:29 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/misc/reqpool.cpp
r39517 r39545 293 293 } 294 294 295 static void rtReqPoolCreateNewWorker(RTREQPOOL pPool) 296 { 297 PRTREQPOOLTHREAD pThread = (PRTREQPOOLTHREAD)RTMemAllocZ(sizeof(RTREQPOOLTHREAD)); 298 if (!pThread) 299 return; 300 301 pThread->uBirthNanoTs = RTTimeNanoTS(); 302 pThread->pPool = pPool; 303 pThread->idLastCpu = NIL_RTCPUID; 304 pThread->hThread = NIL_RTTHREAD; 305 RTListInit(&pThread->IdleNode); 306 RTListAppend(&pPool->WorkerThreads, &pThread->ListNode); 307 pPool->cCurThreads++; 308 pPool->cThreadsCreated++; 309 310 static uint32_t s_idThread = 0; 311 int rc = RTThreadCreateF(&pThread->hThread, rtReqPoolThreadProc, pThread, 0 /*default stack size*/, 312 pPool->enmThreadType, RTTHREADFLAGS_WAITABLE, "REQPT%02u", ++s_idThread); 313 if (RT_SUCCESS(rc)) 314 pPool->uLastThreadCreateNanoTs = pThread->uBirthNanoTs; 315 else 316 { 317 pPool->cCurThreads--; 318 RTListNodeRemove(&pThread->ListNode); 319 RTMemFree(pThread); 320 } 321 } 322 295 323 296 324 DECLHIDDEN(int) rtReqPoolSubmit(PRTREQPOOLINT pPool, PRTREQINT pReq) … … 348 376 && (RTTimeNanoTS() - pReq->uSubmitNanoTs) / RT_NS_1MS >= pPool->cMsCurPushBack ) 349 377 { 350 uint32_t const cMsTimeout = pPool->cMsCurPushBack; 351 pPool->cPushingBack++; 352 RTCritSectLeave(&pPool->CritSect); 353 354 /** @todo this is everything but perfect... it makes wake up order 355 * assumptions. A better solution would be having a lazily 356 * allocated push back event on each request. */ 357 int rc = RTSemEventWait(pPool->hPushBackEvt, cMsTimeout); 358 359 RTCritSectEnter(&pPool->CritSect); 360 pPool->cPushingBack--; 361 } 362 363 /* 364 * Create a new thread for processing the request, or should we wait? 365 */ 366 pThread = (PRTREQPOOLTHREAD)RTMemAllocZ(sizeof(RTREQPOOLTHREAD)); 367 if (pThread) 368 { 369 pThread->uBirthNanoTs = RTTimeNanoTS(); 370 pThread->pPool = pPool; 371 pThread->idLastCpu = NIL_RTCPUID; 372 pThread->hThread = NIL_RTTHREAD; 373 RTListInit(&pThread->IdleNode); 374 RTListAppend(&pPool->WorkerThreads, &pThread->ListNode); 375 pPool->cCurThreads++; 376 pPool->cThreadsCreated++; 377 378 static uint32_t s_idThread = 0; 379 int rc = RTThreadCreateF(&pThread->hThread, rtReqPoolThreadProc, pThread, 0 /*default stack size*/, 380 pPool->enmThreadType, RTTHREADFLAGS_WAITABLE, "REQPT%02u", ++s_idThread); 381 if (RT_SUCCESS(rc)) 382 pPool->uLastThreadCreateNanoTs = pThread->uBirthNanoTs; 383 else 378 RTSEMEVENTMULTI hEvt = pReq->hPushBackEvt; 379 if (hEvt == NIL_RTSEMEVENTMULTI) 384 380 { 385 pPool->cCurThreads--; 386 RTListNodeRemove(&pThread->ListNode); 387 RTMemFree(pThread); 381 int rc = RTSemEventMultiCreate(&hEvt); 382 if (RT_SUCCESS(rc)) 383 pReq->hPushBackEvt = hEvt; 384 else 385 hEvt = NIL_RTSEMEVENTMULTI; 386 } 387 if (hEvt != NIL_RTSEMEVENTMULTI) 388 { 389 uint32_t const cMsTimeout = pPool->cMsCurPushBack; 390 pPool->cPushingBack++; 391 RTCritSectLeave(&pPool->CritSect); 392 393 /** @todo this is everything but perfect... it makes wake up order 394 * assumptions. A better solution would be having a lazily 395 * allocated push back event on each request. */ 396 int rc = RTSemEventWait(pPool->hPushBackEvt, cMsTimeout); 397 398 RTCritSectEnter(&pPool->CritSect); 399 pPool->cPushingBack--; 400 /** @todo check if it's still on the list before going on. */ 388 401 } 389 402 } 403 404 /* 405 * Create a new thread for processing the request. 406 * For simplicity, we don't bother leaving the critical section while doing so. 407 */ 408 rtReqPoolCreateNewWorker(pPool); 409 390 410 RTCritSectLeave(&pPool->CritSect); 391 392 411 return VINF_SUCCESS; 393 412 }
Note:
See TracChangeset
for help on using the changeset viewer.