Skip to content

Commit

Permalink
remove dependency on boost::thread
Browse files Browse the repository at this point in the history
instances of boost::thread and boost::mutex are all replaced by std versions.
This means we don't need to link with boost::thread anymore.

This should reduce boost version conflicts, such as those in #429 and #241.
  • Loading branch information
KrisThielemans committed Sep 13, 2019
1 parent 1552deb commit a3162d1
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 30 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ endif(APPLE)

#### we need the boost library from boost.org
set(BOOST_ROOT CACHE PATH "root of Boost")
find_package(Boost 1.36.0 COMPONENTS system filesystem thread date_time chrono REQUIRED)
find_package(Boost 1.36.0 COMPONENTS system filesystem REQUIRED)
# For Visual Studio we have to disable the auto-linking feature of boost
# where just including a boost file automatically adds it to the linker path.
# Although this sounds great, it sadly breaks because of conflicting file-paths when linking etc etc.
Expand Down
8 changes: 4 additions & 4 deletions src/xGadgetron/cGadgetron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#
#=========================================================================
# Commented out, as this is now done at the top-level
#find_package(Boost COMPONENTS system filesystem thread date_time chrono REQUIRED)
#find_package(Boost COMPONENTS system filesystem REQUIRED)
# For Visual Studio we have to disable the auto-linking feature of boost
# where just including a boost file automatically adds it to the linker path.
# Although this sounds great, it sadly breaks because of conflicting file-paths when linking etc etc.
Expand All @@ -28,7 +28,7 @@
if (SIRF_INSTALL_DEPENDENCIES AND WIN32)
set(Boost_DLL_DIR ${Boost_LIBRARY_DIR_RELEASE})
message(STATUS "Install boost shared libraries from ${Boost_DLL_DIR} ")
foreach (__boost_lib system filesystem thread date_time chrono)
foreach (__boost_lib system filesystem)
file(GLOB Boost_DLL "${Boost_DLL_DIR}/boost_${__boost_lib}*.dll")
install( FILES ${Boost_DLL} DESTINATION bin )
endforeach()
Expand All @@ -50,13 +50,13 @@ target_link_libraries(cgadgetron iutilities csirf)
if((CMAKE_VERSION VERSION_LESS 3.5.0) OR (NOT _Boost_IMPORTED_TARGETS))
# This is harder than it should be on older CMake versions to be able to cope with
# spaces in filenames.
foreach(C SYSTEM FILESYSTEM THREAD DATE_TIME CHRONO)
foreach(C SYSTEM FILESYSTEM)
target_link_libraries(cgadgetron optimized "${Boost_${C}_LIBRARY_RELEASE}")
target_link_libraries(cgadgetron debug "${Boost_${C}_LIBRARY_DEBUG}")
endforeach()
else()
# Nice and simple for recent CMake (which knows about your Boost version)
target_link_libraries(cgadgetron Boost::system Boost::filesystem Boost::thread Boost::date_time Boost::chrono)
target_link_libraries(cgadgetron Boost::system Boost::filesystem)
endif()

# Note: cannot use ISMRMRD_LIBRARIES on Windows as it generally contains
Expand Down
6 changes: 3 additions & 3 deletions src/xGadgetron/cGadgetron/cgadgetron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ return NEW_OBJECT_HANDLE(G)
#define NEW_GADGET_CHAIN(C) if (boost::iequals(name, C::class_name())) \
return NEW_OBJECT_HANDLE(C)

shared_ptr<boost::mutex> Mutex::sptr_mutex_;
shared_ptr<std::mutex> Mutex::sptr_mutex_;

static void*
unknownObject(const char* obj, const char* name, const char* file, int line)
Expand Down Expand Up @@ -1237,7 +1237,7 @@ cGT_sendAcquisitions(void* ptr_con, void* ptr_dat)
GTConnector& conn = objectFromHandle<GTConnector>(h_con);
GadgetronClientConnector& con = conn();
Mutex mutex;
boost::mutex& mtx = mutex();
std::mutex& mtx = mutex();
ISMRMRD::Dataset& ismrmrd_dataset =
objectFromHandle<ISMRMRD::Dataset>(h_dat);

Expand All @@ -1253,7 +1253,7 @@ cGT_sendAcquisitions(void* ptr_con, void* ptr_dat)
ISMRMRD::Acquisition acq_tmp;
for (uint32_t i = 0; i < acquisitions; i++) {
{
boost::mutex::scoped_lock scoped_lock(mtx);
std::unique_lock<std::mutex> scoped_lock(mtx);
ismrmrd_dataset.readAcquisition(i, acq_tmp);
}
con.send_ismrmrd_acquisition(acq_tmp);
Expand Down
2 changes: 1 addition & 1 deletion src/xGadgetron/cGadgetron/gadgetron_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ GadgetronClientConnector::connect(std::string hostname, std::string port)
throw GadgetronClientException("Error connecting using socket.");

reader_thread_ =
boost::thread(boost::bind(&GadgetronClientConnector::read_task, this));
std::thread(&GadgetronClientConnector::read_task, this);
}

void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ limitations under the License.
#include <thread>

#include <boost/asio.hpp>
#include <boost/thread/thread.hpp>

#include <ismrmrd/dataset.h>
#include <ismrmrd/ismrmrd.h>
Expand Down Expand Up @@ -260,7 +259,7 @@ namespace sirf {

boost::asio::io_service io_service;
boost::asio::ip::tcp::socket* socket_;
boost::thread reader_thread_;
std::thread reader_thread_;
maptype readers_;
unsigned int timeout_ms_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ limitations under the License.
#include <chrono>
#include <complex>

#include <boost/thread/mutex.hpp>
#include <mutex>

#include "sirf/Gadgetron/cgadgetron_shared_ptr.h"

Expand Down Expand Up @@ -106,11 +106,11 @@ namespace sirf {
{
init_();
}
boost::mutex& operator()()
std::mutex& operator()()
{
return *sptr_mutex_.get();
}
gadgetron::shared_ptr<boost::mutex> sptr()
gadgetron::shared_ptr<std::mutex> sptr()
{
return sptr_mutex_;
}
Expand All @@ -123,17 +123,17 @@ namespace sirf {
sptr_mutex_->unlock();
}
private:
static gadgetron::shared_ptr<boost::mutex> sptr_mutex_;
static gadgetron::shared_ptr<std::mutex> sptr_mutex_;
static void init_()
{
static bool initialized = false;
if (!initialized) {
sptr_mutex_ = gadgetron::shared_ptr<boost::mutex>(new boost::mutex);
sptr_mutex_ = gadgetron::shared_ptr<std::mutex>(new std::mutex);
initialized = true;
}
}
};

}

#endif
#endif
2 changes: 1 addition & 1 deletion src/xGadgetron/mGadgetron/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

if(BUILD_MATLAB)
#commented out as done at top-level
#find_package(Boost COMPONENTS system thread filesystem REQUIRED)
#find_package(Boost COMPONENTS system filesystem REQUIRED)

set(CMAKE_POSITION_INDEPENDENT_CODE True)

Expand Down
12 changes: 0 additions & 12 deletions src/xSTIR/cSTIR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,5 @@ target_include_directories(cstir PUBLIC "${STIR_INCLUDE_DIRS}")

target_link_libraries(cstir csirf iutilities)
target_link_libraries(cstir "${STIR_LIBRARIES}")
# Add boost library dependencies
if((CMAKE_VERSION VERSION_LESS 3.5.0) OR (NOT _Boost_IMPORTED_TARGETS))
# This is harder than it should be on older CMake versions to be able to cope with
# spaces in filenames.
foreach(C SYSTEM FILESYSTEM THREAD DATE_TIME CHRONO)
target_link_libraries(cstir optimized "${Boost_${C}_LIBRARY_RELEASE}")
target_link_libraries(cstir debug "${Boost_${C}_LIBRARY_DEBUG}")
endforeach()
else()
# Nice and simple for recent CMake (which knows about your Boost version)
target_link_libraries(cstir Boost::system Boost::filesystem Boost::thread Boost::date_time Boost::chrono)
endif()

ADD_SUBDIRECTORY(tests)

0 comments on commit a3162d1

Please sign in to comment.