Skip to content

Commit

Permalink
Merge pull request #39 from sy-c/master
Browse files Browse the repository at this point in the history
v1.5.0
  • Loading branch information
sy-c authored and Sylvain committed Nov 4, 2020
2 parents bdab0c4 + 9f71710 commit 4300191
Show file tree
Hide file tree
Showing 41 changed files with 1,058 additions and 1,421 deletions.
11 changes: 1 addition & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ else()
endif()

project(Common
VERSION 0.0.0
VERSION 1.5.0
DESCRIPTION "O2 Common library"
LANGUAGES C CXX
)
Expand Down Expand Up @@ -90,8 +90,6 @@ add_library(Common
src/Thread.cxx
src/Timer.cxx
src/Configuration.cxx
src/DataBlock.cxx
src/DataBlockContainer.cxx
src/MemPool.cxx)

# Produce the final Version.h using template Version.h.in and substituting
Expand Down Expand Up @@ -120,12 +118,6 @@ add_subdirectory(doc)
####################################
enable_testing()

add_executable(testDataFormat test/testDataFormat.c)
target_link_libraries(testDataFormat Common)
set_source_files_properties(test/testDataFormat.c PROPERTIES LANGUAGE CXX)
add_test(NAME testDataFormat COMMAND testDataFormat)
set_tests_properties(testDataFormat PROPERTIES TIMEOUT 60)

add_executable(testSimpleLog test/testSimpleLog.cxx)
target_link_libraries(testSimpleLog Common)

Expand All @@ -136,7 +128,6 @@ set(TEST_SRCS
test/TestSuffixNumber.cxx
test/TestSuffixOption.cxx
test/TestSystem.cxx
test/testMemPool.cxx
test/testTimer.cxx
)

Expand Down
69 changes: 33 additions & 36 deletions include/Common/BasicThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,46 @@ namespace Common
/// the function should stop its work.
class BasicThread
{
public:
public:
/// Start thread
/// \param stopFlag Pointer to flag indicating the function should stop
void start(std::function<void(std::atomic<bool>* stopFlag)> function)
{
join();
mStopFlag = false;
mThread = std::thread(function, &mStopFlag);
}

/// Start thread
/// \param stopFlag Pointer to flag indicating the function should stop
void start(std::function<void(std::atomic<bool>* stopFlag)> function)
{
join();
mStopFlag = false;
mThread = std::thread(function, &mStopFlag);
}
void stop()
{
mStopFlag = true;
}

void stop()
{
mStopFlag = true;
void join()
{
stop();
if (mThread.joinable()) {
mThread.join();
}
}

void join()
{
stop();
if (mThread.joinable()) {
mThread.join();
}
}

~BasicThread()
{
try {
join();
}
catch (const std::system_error& e) {
std::cout << "Failed to join thread: " << e.what() << '\n';
}
catch (const std::exception& e) {
std::cout << "Unexpected exception while joining thread: " << e.what() << '\n';
}
~BasicThread()
{
try {
join();
} catch (const std::system_error& e) {
std::cout << "Failed to join thread: " << e.what() << '\n';
} catch (const std::exception& e) {
std::cout << "Unexpected exception while joining thread: " << e.what() << '\n';
}
}

private:
/// Thread object
std::thread mThread;
private:
/// Thread object
std::thread mThread;

/// Flag to stop the thread
std::atomic<bool> mStopFlag;
/// Flag to stop the thread
std::atomic<bool> mStopFlag;
};

} // namespace Common
Expand Down
Loading

0 comments on commit 4300191

Please sign in to comment.