Repository navigation
Expand file tree
/
Copy pathStubExecutor.cpp
More file actions
65 lines (51 loc) · 1.51 KB
/
Copy pathStubExecutor.cpp
File metadata and controls
65 lines (51 loc) · 1.51 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
54
55
56
57
58
59
60
61
62
63
64
65
#include "stdafx.h"
#include "StubExecutor.h"
namespace Disruptor
{
namespace Tests
{
std::future< void > StubExecutor::execute(const std::function< void() >& command)
{
++m_executionCount;
std::future< void > result;
if (!m_ignoreExecutions)
{
std::packaged_task< void() > task(command);
result = task.get_future();
std::lock_guard< decltype(m_mutex) > lock(m_mutex);
m_threads.push_back(boost::thread(std::move(task)));
}
return result;
}
void StubExecutor::joinAllThreads()
{
std::lock_guard< decltype(m_mutex) > lock(m_mutex);
while (!m_threads.empty())
{
boost::thread thread(std::move(m_threads.front()));
m_threads.pop_front();
if (thread.joinable())
{
try
{
thread.interrupt();
thread.timed_join(boost::posix_time::milliseconds(5000));
}
catch (std::exception& ex)
{
std::cout << ex.what() << std::endl;
}
}
BOOST_CHECK_MESSAGE(thread.joinable() == false, "Failed to stop thread: " << thread.get_id());
}
}
void StubExecutor::ignoreExecutions()
{
m_ignoreExecutions = true;
}
std::int32_t StubExecutor::getExecutionCount() const
{
return m_executionCount;
}
} // namespace Tests
} // namespace Disruptor