Skip to content

Commit 4300191

Browse files
sy-cSylvain
authored andcommitted
Merge pull request #39 from sy-c/master
v1.5.0
2 parents bdab0c4 + 9f71710 commit 4300191

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1058
-1421
lines changed

CMakeLists.txt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ else()
99
endif()
1010

1111
project(Common
12-
VERSION 0.0.0
12+
VERSION 1.5.0
1313
DESCRIPTION "O2 Common library"
1414
LANGUAGES C CXX
1515
)
@@ -90,8 +90,6 @@ add_library(Common
9090
src/Thread.cxx
9191
src/Timer.cxx
9292
src/Configuration.cxx
93-
src/DataBlock.cxx
94-
src/DataBlockContainer.cxx
9593
src/MemPool.cxx)
9694

9795
# Produce the final Version.h using template Version.h.in and substituting
@@ -120,12 +118,6 @@ add_subdirectory(doc)
120118
####################################
121119
enable_testing()
122120

123-
add_executable(testDataFormat test/testDataFormat.c)
124-
target_link_libraries(testDataFormat Common)
125-
set_source_files_properties(test/testDataFormat.c PROPERTIES LANGUAGE CXX)
126-
add_test(NAME testDataFormat COMMAND testDataFormat)
127-
set_tests_properties(testDataFormat PROPERTIES TIMEOUT 60)
128-
129121
add_executable(testSimpleLog test/testSimpleLog.cxx)
130122
target_link_libraries(testSimpleLog Common)
131123

@@ -136,7 +128,6 @@ set(TEST_SRCS
136128
test/TestSuffixNumber.cxx
137129
test/TestSuffixOption.cxx
138130
test/TestSystem.cxx
139-
test/testMemPool.cxx
140131
test/testTimer.cxx
141132
)
142133

include/Common/BasicThread.h

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,46 @@ namespace Common
2323
/// the function should stop its work.
2424
class BasicThread
2525
{
26-
public:
26+
public:
27+
/// Start thread
28+
/// \param stopFlag Pointer to flag indicating the function should stop
29+
void start(std::function<void(std::atomic<bool>* stopFlag)> function)
30+
{
31+
join();
32+
mStopFlag = false;
33+
mThread = std::thread(function, &mStopFlag);
34+
}
2735

28-
/// Start thread
29-
/// \param stopFlag Pointer to flag indicating the function should stop
30-
void start(std::function<void(std::atomic<bool>* stopFlag)> function)
31-
{
32-
join();
33-
mStopFlag = false;
34-
mThread = std::thread(function, &mStopFlag);
35-
}
36+
void stop()
37+
{
38+
mStopFlag = true;
39+
}
3640

37-
void stop()
38-
{
39-
mStopFlag = true;
41+
void join()
42+
{
43+
stop();
44+
if (mThread.joinable()) {
45+
mThread.join();
4046
}
47+
}
4148

42-
void join()
43-
{
44-
stop();
45-
if (mThread.joinable()) {
46-
mThread.join();
47-
}
48-
}
49-
50-
~BasicThread()
51-
{
52-
try {
53-
join();
54-
}
55-
catch (const std::system_error& e) {
56-
std::cout << "Failed to join thread: " << e.what() << '\n';
57-
}
58-
catch (const std::exception& e) {
59-
std::cout << "Unexpected exception while joining thread: " << e.what() << '\n';
60-
}
49+
~BasicThread()
50+
{
51+
try {
52+
join();
53+
} catch (const std::system_error& e) {
54+
std::cout << "Failed to join thread: " << e.what() << '\n';
55+
} catch (const std::exception& e) {
56+
std::cout << "Unexpected exception while joining thread: " << e.what() << '\n';
6157
}
58+
}
6259

63-
private:
64-
/// Thread object
65-
std::thread mThread;
60+
private:
61+
/// Thread object
62+
std::thread mThread;
6663

67-
/// Flag to stop the thread
68-
std::atomic<bool> mStopFlag;
64+
/// Flag to stop the thread
65+
std::atomic<bool> mStopFlag;
6966
};
7067

7168
} // namespace Common

0 commit comments

Comments
 (0)