UtilsLite
Utilities for C++ programming
Loading...
Searching...
No Matches
ThreadPool0.hxx
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*\
2 | |
3 | Copyright (C) 2020 |
4 | |
5 | , __ , __ |
6 | /|/ \ /|/ \ |
7 | | __/ _ ,_ | __/ _ ,_ |
8 | | \|/ / | | | | \|/ / | | | |
9 | |(__/|__/ |_/ \_/|/|(__/|__/ |_/ \_/|/ |
10 | /| /| |
11 | \| \| |
12 | |
13 | Enrico Bertolazzi |
14 | Dipartimento di Ingegneria Industriale |
15 | Università degli Studi di Trento |
16 | email: enrico.bertolazzi@unitn.it |
17 | |
18\*--------------------------------------------------------------------------*/
19
20//
21// file: ThreadPool0.hxx
22//
23
24#ifdef UTILS_OS_LINUX
25 #include <pthread.h>
26#endif
27
28namespace Utils {
29
34
35 /*\
36 | _____ _ _ ____ _
37 | |_ _| |__ _ __ ___ __ _ __| | _ \ ___ ___ | |
38 | | | | '_ \| '__/ _ \/ _` |/ _` | |_) / _ \ / _ \| |
39 | | | | | | | | | __/ (_| | (_| | __/ (_) | (_) | |
40 | |_| |_| |_|_| \___|\__,_|\__,_|_| \___/ \___/|_|
41 \*/
42
53 class ThreadPool0 : public ThreadPoolBase {
55 unsigned n_thread{1};
56
57 public:
58
66 explicit
67 ThreadPool0( unsigned n )
68 : ThreadPoolBase(), n_thread{n}
69 {}
70
72 virtual ~ThreadPool0() = default;
73
82 void exec( FUN && fun ) override { fun(); }
83
90 void wait() override { }
91
100 unsigned thread_count() const override { return n_thread; }
101
109 static char const * Name() { return "ThreadPool0 (fake thread)"; }
110
111 char const * name() const override { return Name(); }
112 };
113
115
116}
117
118//
119// eof: ThreadPool0.hxx
120//
char const * name() const override
Definition ThreadPool0.hxx:111
void exec(FUN &&fun) override
Executes a given function in the current thread.
Definition ThreadPool0.hxx:82
unsigned thread_count() const override
Returns the number of threads in the pool.
Definition ThreadPool0.hxx:100
static char const * Name()
Returns the name of the thread pool.
Definition ThreadPool0.hxx:109
virtual ~ThreadPool0()=default
Destructor.
ThreadPool0(unsigned n)
Constructs a fake thread pool with a specified number of threads.
Definition ThreadPool0.hxx:67
void wait() override
No-op method to wait for all tasks to complete.
Definition ThreadPool0.hxx:90
ThreadPoolBase(ThreadPoolBase const &)=delete
std::function< void(void)> FUN
Definition ThreadPoolBase.hxx:55
Definition SystemUtils.cc:39