LeechCraft 0.6.70-17335-ge406ffdcaf
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
workerthreadbase.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "workerthreadbase.h"
11
12namespace LC::Util
13{
14 void WorkerThreadBase::SetPaused (bool paused)
15 {
16 if (paused == IsPaused_)
17 return;
18
19 IsPaused_ = paused;
20 if (!paused)
21 emit rotateFuncs ();
22 }
23
25 {
26 QMutexLocker locker { &FunctionsMutex_ };
27 return Functions_.size ();
28 }
29
31 {
33 {
34 [this] { RotateFuncs (); },
35 this,
36 SIGNAL (rotateFuncs ()),
37 nullptr
38 };
39
40 Initialize ();
41
42 RotateFuncs ();
43
44 QThread::run ();
45
46 Cleanup ();
47 }
48
49 void WorkerThreadBase::RotateFuncs ()
50 {
51 if (IsPaused_)
52 return;
53
54 decltype (Functions_) funcs;
55
56 {
57 QMutexLocker locker { &FunctionsMutex_ };
58
59 using std::swap;
60 swap (funcs, Functions_);
61 }
62
63 for (const auto& func : funcs)
64 func ();
65 }
66}
Executes a given functor upon a signal (or a list of signals).
Definition slotclosure.h:81
virtual void Initialize()=0
virtual void Cleanup()=0
void swap(FDGuard &g1, FDGuard &g2)
Definition fdguard.cpp:51