MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / addWork

Method addWork

source/core/StarWorkerPool.cpp:105–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105WorkerPoolHandle WorkerPool::addWork(function<void()> work) {
106 // Construct a worker pool handle and wrap the work to signal the handle when
107 // finished. Set the result to empty string if successful and to the content
108 // of the exception if an exception is thrown.
109 auto workerPoolHandleImpl = make_shared<WorkerPoolHandle::Impl>();
110 queueWork([workerPoolHandleImpl, work]() {
111 try {
112 work();
113 MutexLocker handleLocker(workerPoolHandleImpl->mutex);
114 workerPoolHandleImpl->done = true;
115 workerPoolHandleImpl->condition.broadcast();
116 } catch (...) {
117 MutexLocker handleLocker(workerPoolHandleImpl->mutex);
118 workerPoolHandleImpl->done = true;
119 workerPoolHandleImpl->exception = std::current_exception();
120 workerPoolHandleImpl->condition.broadcast();
121 }
122 });
123
124 return workerPoolHandleImpl;
125}
126
127WorkerPool::WorkerThread::WorkerThread(WorkerPool* parent)
128 : Thread(strf("WorkerThread for WorkerPool '{}'", parent->m_name)),

Callers 2

fullyLoadMethod · 0.80
TESTFunction · 0.80

Calls 1

broadcastMethod · 0.45

Tested by 1

TESTFunction · 0.64