MCPcopy Create free account
hub / github.com/PDAL/PDAL / add

Function add

pdal/util/ThreadPool.hpp:129–147  ·  view source on GitHub ↗

Add a threaded task, blocking until a thread is available. If join() is called, add() may not be called again until go() is called and completes.

Source from the content-addressed store, hash-verified

127 // Add a threaded task, blocking until a thread is available. If join() is
128 // called, add() may not be called again until go() is called and completes.
129 PDAL_EXPORT void add(std::function<void()> task)
130 {
131 std::unique_lock<std::mutex> lock(m_mutex);
132 if (!m_running)
133 {
134 throw pdal_error("Attempted to add a task to a stopped ThreadPool");
135 }
136
137 m_produceCv.wait(lock, [this]()
138 {
139 return m_queueSize < 0 || m_tasks.size() < (size_t)m_queueSize;
140 });
141
142 m_tasks.emplace(task);
143
144 // Notify worker that a task is available.
145 lock.unlock();
146 m_consumeCv.notify_all();
147 }
148
149 PDAL_EXPORT std::size_t size() const
150 { return m_numThreads; }

Callers 1

ArgValListMethod · 0.70

Calls 3

waitMethod · 0.80
unlockMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected