Skip to content

Commit

Permalink
Use c++11 instead of boost
Browse files Browse the repository at this point in the history
This package uses only a small amount of boost
for a mutex and scoped_lock.
These are replaced with std::mutex
and std::lock_guard from c++11.
Boost is removed as a dependency
and the c++11 compiler flag is added.
  • Loading branch information
scpeters committed Dec 14, 2015
1 parent 4800600 commit deb968d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
11 changes: 3 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,21 @@ if (HAS_VISIBILITY)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
endif()

find_package(Boost COMPONENTS system thread REQUIRED)
# Use c++11 compiler flag, since it's needed for console.cpp
# It isn't in a header file, so it doesn't need to be exported
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++11")

if(MSVC OR MSVC90 OR MSVC10)
set(MSVC ON)
endif (MSVC OR MSVC90 OR MSVC10)

if(MSVC)
add_definitions(-DBOOST_ALL_NO_LIB)
endif(MSVC)

include_directories(include)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIRS})

if(NOT DEFINED BUILD_SHARED_LIBS)
option(BUILD_SHARED_LIBS "Build dynamically-linked binaries" ON)
endif()

add_library(${PROJECT_NAME} src/console.cpp)
target_link_libraries(${PROJECT_NAME} ${Boost_LIBRARIES})

install(TARGETS ${PROJECT_NAME}
DESTINATION lib/)
Expand Down
6 changes: 3 additions & 3 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/* Author: Ryan Luna, Ioan Sucan */

#include "console_bridge/console.h"
#include <boost/thread/mutex.hpp>
#include <mutex>
#include <iostream>
#include <cstdio>
#include <cstdarg>
Expand All @@ -55,7 +55,7 @@ struct DefaultOutputHandler
console_bridge::OutputHandler *output_handler_;
console_bridge::OutputHandler *previous_output_handler_;
console_bridge::LogLevel logLevel_;
boost::mutex lock_; // it is likely the outputhandler does some I/O, so we serialize it
std::mutex lock_; // it is likely the outputhandler does some I/O, so we serialize it
};

// we use this function because we want to handle static initialization correctly
Expand All @@ -70,7 +70,7 @@ static DefaultOutputHandler* getDOH(void)

#define USE_DOH \
DefaultOutputHandler *doh = getDOH(); \
boost::mutex::scoped_lock slock(doh->lock_)
std::lock_guard<std::mutex> slock(doh->lock_)

#define MAX_BUFFER_SIZE 1024

Expand Down

0 comments on commit deb968d

Please sign in to comment.