Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
LogWorker.cpp
Go to the documentation of this file.
1/*
2* This file is part of Project SkyFire https://www.projectskyfire.org.
3* See LICENSE.md file for Copyright information
4*/
5
6#include "LogWorker.h"
8
9#include <mutex>
10
22
24 : m_impl(new Impl)
25{
26 if (m_impl->threadGroup.Start(1) == -1)
27 m_impl->active = false;
28}
29
31{
32 {
33 std::lock_guard<std::mutex> guard(m_impl->queueLock);
34 m_impl->active = false;
35 }
36
37 m_impl->threadGroup.DrainAndJoin();
38}
39
41{
42 if (!op)
43 return -1;
44
45 {
46 std::lock_guard<std::mutex> guard(m_impl->queueLock);
47
48 if (!m_impl->active)
49 return -1;
50 }
51
52 m_impl->threadGroup.GetExecutor().Post(
53 [op]
54 {
55 op->call();
56 delete op;
57 });
58
59 return 0;
60}
std::unique_ptr< Impl > m_impl
Definition LogWorker.h:30
int enqueue(LogOperation *op)
Definition LogWorker.cpp:40
Skyfire::Asio::IoContextThreadGroup threadGroup
Definition LogWorker.cpp:18
std::mutex queueLock
Definition LogWorker.cpp:19