MCPcopy Create free account
hub / github.com/Icinga/icinga2 / EnqueueUnlocked

Method EnqueueUnlocked

lib/base/workqueue.cpp:57–80  ·  view source on GitHub ↗

* Enqueues a task. Tasks are guaranteed to be executed in the order * they were enqueued in except if there is more than one worker thread. */

Source from the content-addressed store, hash-verified

55 * they were enqueued in except if there is more than one worker thread.
56 */
57void WorkQueue::EnqueueUnlocked(std::unique_lock<std::mutex>& lock, std::function<void ()>&& function, WorkQueuePriority priority)
58{
59 if (!m_Spawned) {
60 Log(LogNotice, "WorkQueue")
61 << "Spawning WorkQueue threads for '" << m_Name << "'";
62
63 for (int i = 0; i < m_ThreadCount; i++) {
64 m_Threads.create_thread([this]() { WorkerThreadProc(); });
65 }
66
67 m_Spawned = true;
68 }
69
70 bool wq_thread = IsWorkerThread();
71
72 if (!wq_thread) {
73 while (m_Tasks.size() >= m_MaxItems && m_MaxItems != 0)
74 m_CVFull.wait(lock);
75 }
76
77 m_Tasks.emplace(std::move(function), priority, ++m_NextTaskID);
78
79 m_CVEmpty.notify_one();
80}
81
82/**
83 * Enqueues a task. Tasks are guaranteed to be executed in the order

Callers

nothing calls this directly

Calls 3

LogClass · 0.85
emplaceMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected