forked from sttp/cppapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadPool.h
More file actions
53 lines (47 loc) · 2.1 KB
/
ThreadPool.h
File metadata and controls
53 lines (47 loc) · 2.1 KB
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
47
48
49
50
51
52
53
//******************************************************************************************************
// ThreadPool.h - Gbtc
//
// Copyright © 2020, Grid Protection Alliance. All Rights Reserved.
//
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
// file except in compliance with the License. You may obtain a copy of the License at:
//
// http://opensource.org/licenses/MIT
//
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
// License for the specific language governing permissions and limitations.
//
// Code Modification History:
// ----------------------------------------------------------------------------------------------------
// 12/27/2020 - J. Ritchie Carroll
// Generated original version of source code.
//
//******************************************************************************************************
#pragma once
#include <unordered_set>
#include "ThreadSafeQueue.h"
#include "Timer.h"
namespace sttp
{
// Defines a simple thread queue that allows actions to be executed with an optional delay
class ThreadPool final // NOLINT
{
private:
std::unordered_set<TimerPtr> m_waitTimers;
Mutex m_waitTimersLock;
Thread m_removeCompletedTimersThread;
ThreadSafeQueue<TimerPtr> m_completedTimers;
std::atomic_bool m_disposing;
public:
ThreadPool();
~ThreadPool() noexcept;
void ShutDown();
void Queue(const std::function<void()>& action);
void Queue(void* state, const std::function<void(void*)>& action);
void Queue(uint32_t delay, const std::function<void()>& action);
void Queue(uint32_t delay, void* state, const std::function<void(void*)>& action);
};
}