MCPcopy Create free account
hub / github.com/SFML/SFML / threadFunction

Function threadFunction

examples/island/Island.cpp:338–379  ·  view source on GitHub ↗

/////////////////////////////////////////////////////// Worker thread entry point. We use a thread pool to avoid the heavy cost of constantly recreating and starting new threads whenever we need to regenerate the terrain. ///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

336///
337////////////////////////////////////////////////////////////
338void threadFunction()
339{
340 std::vector<sf::Vertex> vertices(resolution.x * rowBlockSize * 6);
341
342 WorkItem workItem = {nullptr, 0};
343
344 // Loop until the application exits
345 for (;;)
346 {
347 workItem.targetBuffer = nullptr;
348
349 // Check if there are new work items in the queue
350 {
351 const std::lock_guard lock(workQueueMutex);
352
353 if (!workPending)
354 return;
355
356 if (!workQueue.empty())
357 {
358 workItem = workQueue.front();
359 workQueue.pop();
360 }
361 }
362
363 // If we didn't receive a new work item, keep looping
364 if (!workItem.targetBuffer)
365 {
366 sf::sleep(sf::milliseconds(10));
367
368 continue;
369 }
370
371 processWorkItem(vertices, workItem);
372
373 {
374 const std::lock_guard lock(workQueueMutex);
375
376 --pendingWorkCount;
377 }
378 }
379}
380
381
382////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 2

sleepFunction · 0.85
processWorkItemFunction · 0.85

Tested by

no test coverage detected