blob: 8f3c8514b5713cf0477193bfff44cf5e4fdecf95 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
/**
* @file threadpool.h
* @author Nat Goodspeed
* @date 2021-10-21
* @brief ThreadPool configures a WorkQueue along with a pool of threads to
* service it.
*
* $LicenseInfo:firstyear=2021&license=viewerlgpl$
* Copyright (c) 2021, Linden Research, Inc.
* $/LicenseInfo$
*/
#if ! defined(LL_THREADPOOL_H)
#define LL_THREADPOOL_H
#include "workqueue.h"
#include <string>
#include <thread>
#include <utility> // std::pair
#include <vector>
namespace LL
{
class ThreadPool
{
public:
/**
* Pass ThreadPool a string name. This can be used to look up the
* relevant WorkQueue.
*/
ThreadPool(const std::string& name, size_t threads=1);
~ThreadPool();
void close();
private:
void run(const std::string& name);
WorkQueue mQueue;
std::string mName;
std::vector<std::pair<std::string, std::thread>> mThreads;
};
} // namespace LL
#endif /* ! defined(LL_THREADPOOL_H) */
|