Skip to content

Commit d0f62d4

Browse files
committed
Merge remote-tracking branch 'upstream/master' into dev-speedy
2 parents 4bfec09 + fab7754 commit d0f62d4

Some content is hidden

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

43 files changed

+498
-475
lines changed

.travis.yml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,13 @@ matrix:
77
- os: osx
88
osx_image: xcode10.1
99
env: OSXVER=MacOS10.13
10-
- os: osx
11-
osx_image: xcode9.2
12-
env: OSXVER=MacOS10.12
13-
- os: osx
14-
osx_image: xcode8
15-
env: OSXVER=MacOS10.11
1610
before_script:
1711
- brew update
1812
- brew upgrade cmake
1913
script:
20-
- mkdir -p build/install
21-
- cd build
2214
- cmake --version
23-
- cmake -DCMAKE_BUILD_TYPE=Release -DLSL_UNIXFOLDERS=1 ${CMakeArgs} -DLSL_UNITTESTS=1 ../
15+
- cmake -S . -B build ${CMakeArgs} -DLSL_UNITTESTS=1
16+
- cd build
2417
- cmake --build . --config Release --target install
2518
- testing/lsl_test_internal || true
2619
- testing/lsl_test_exported

CMakeLists.txt

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ set(LSL_WINVER "0x0601" CACHE STRING
2525
"Windows version (_WIN32_WINNT) to target (defaults to 0x0601 for Windows 7)")
2626

2727
# Add an object library so all files are only compiled once
28-
set(lslobj_sources
28+
add_library(lslobj OBJECT
2929
src/api_config.cpp
3030
src/api_config.h
3131
src/api_types.hpp
@@ -96,7 +96,6 @@ set(lslobj_sources
9696
include/lsl/types.h
9797
include/lsl/xml.h
9898
)
99-
add_library(lslobj OBJECT ${lslobj_sources})
10099

101100
# try to find out which revision is currently checked out
102101
find_package(Git)
@@ -120,11 +119,9 @@ else()
120119
set(lslgitrevision "unknown")
121120
set(lslgitbranch "unknown")
122121
endif()
123-
set(LSL_VERSION_INFO "\"git:${lslgitrevision}/branch:${lslgitbranch}/build:${CMAKE_BUILD_TYPE}/compiler:${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}/boost:\" BOOST_LIB_VERSION")
124-
set_source_files_properties("src/common.cpp" PROPERTIES COMPILE_DEFINITIONS LSL_LIBRARY_INFO_STR=${LSL_VERSION_INFO})
122+
set(LSL_VERSION_INFO "git:${lslgitrevision}/branch:${lslgitbranch}/build:${CMAKE_BUILD_TYPE}/compiler:${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}")
125123
set_source_files_properties("src/loguru/loguru.cpp" PROPERTIES COMPILE_DEFINITIONS LOGURU_STACKTRACES=$<BOOL:${LSL_DEBUGLOG}>)
126124

127-
128125
## create the lslboost target
129126
add_library(lslboost OBJECT
130127
lslboost/asio_objects.cpp
@@ -139,7 +136,7 @@ if (UNIX)
139136
)
140137
find_package(Threads REQUIRED)
141138
target_link_libraries(lslboost PUBLIC Threads::Threads)
142-
target_compile_features(lslboost PUBLIC cxx_std_11)
139+
target_compile_features(lslboost PUBLIC cxx_std_11 cxx_lambda_init_captures)
143140
else () # WIN32
144141
target_sources(lslboost PRIVATE
145142
lslboost/libs/serialization/src/codecvt_null.cpp
@@ -165,7 +162,12 @@ target_include_directories(lslboost PUBLIC
165162
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/lslboost>)
166163

167164

168-
target_link_libraries(lslobj PRIVATE lslboost)
165+
target_link_libraries(lslobj
166+
PRIVATE
167+
lslboost
168+
PUBLIC
169+
$<$<AND:$<BOOL:${LSL_DEBUGLOG}>,$<PLATFORM_ID:Linux>>:dl>
170+
)
169171
target_include_directories(lslobj
170172
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
171173
)
@@ -176,37 +178,24 @@ target_compile_definitions(lslobj
176178
)
177179

178180
# shared library
179-
if (CMAKE_GENERATOR MATCHES "Xcode")
180-
# Xcode is rather annoying in that it doesn't build SHARED libs unless they have source files.
181-
# So we need to build from source, and then add all the other settings missing due to lack of lslobj
182-
add_library(lsl SHARED ${lslobj_sources})
183-
target_link_libraries(lsl PRIVATE lslboost)
184-
else()
185-
add_library(lsl SHARED)
186-
target_link_libraries(lsl
187-
PUBLIC lslobj
188-
PRIVATE lslboost)
189-
endif()
190-
target_include_directories(lsl
191-
PUBLIC
192-
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
193-
$<INSTALL_INTERFACE:include>
194-
)
195-
target_compile_definitions(lsl
196-
PRIVATE LIBLSL_EXPORTS $<$<PLATFORM_ID:Windows>:_CRT_SECURE_NO_WARNINGS>
197-
INTERFACE LSLNOAUTOLINK # don't use #pragma(lib) in CMake builds
198-
)
199-
181+
add_library(lsl SHARED src/buildinfo.cpp)
182+
target_compile_definitions(lsl PRIVATE
183+
LSL_LIBRARY_INFO_STR="${LSL_VERSION_INFO}/link:shared"
184+
LIBLSL_EXPORTS)
185+
target_link_libraries(lsl
186+
PUBLIC lslobj
187+
PRIVATE lslboost)
200188
set_target_properties(lsl PROPERTIES
201189
VERSION ${liblsl_VERSION_MAJOR}.${liblsl_VERSION_MINOR}.${liblsl_VERSION_PATCH}
202190
)
203191

204192
set(LSL_EXPORT_TARGETS lsl lslobj lslboost)
205193
if(LSL_BUILD_STATIC)
206-
add_library(lsl-static STATIC)
194+
add_library(lsl-static STATIC src/buildinfo.cpp)
195+
target_compile_definitions(lsl-static PRIVATE LSL_LIBRARY_INFO_STR="${LSL_VERSION_INFO}/link:static")
207196
target_link_libraries(lsl-static PUBLIC lslobj PRIVATE lslboost)
208197
# for LSL_CPP_API export header
209-
target_compile_definitions(lsl-static INTERFACE LIBLSL_STATIC)
198+
target_compile_definitions(lsl-static PUBLIC LIBLSL_STATIC)
210199
endif()
211200

212201
if(LSL_FORCE_FANCY_LIBNAME)

include/lsl/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ extern LIBLSL_C_API int32_t lsl_library_version();
171171
*
172172
* The format of the string shouldn't be used for anything important except giving a debugging
173173
* person a good idea which exact library version is used. */
174-
extern LIBLSL_C_API const char *lsl_library_info();
174+
extern LIBLSL_C_API const char *lsl_library_info(void);
175175

176176
/**
177177
* Obtain a local system time stamp in seconds.

src/api_config.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#include "api_config.h"
22
#include "common.h"
33
#include "inireader.h"
4-
#include <boost/thread/once.hpp>
4+
#include <algorithm>
55
#include <fstream>
6+
#include <mutex>
67

78
using namespace lsl;
89

@@ -76,7 +77,10 @@ void api_config::load_from_file(const std::string &filename) {
7677
INI pt;
7778
if (!filename.empty()) {
7879
std::ifstream infile(filename);
79-
if (infile.good()) pt.load(infile);
80+
if (infile.good()) {
81+
LOG_F(INFO, "Loading configuration from %s", filename.c_str());
82+
pt.load(infile);
83+
}
8084
}
8185

8286
// read out the [ports] parameters
@@ -206,7 +210,7 @@ void api_config::load_from_file(const std::string &filename) {
206210
force_default_timestamps_ = pt.get("tuning.ForceDefaultTimestamps", false);
207211

208212
// read the [log] settings
209-
int log_level = pt.get("log.level", -1);
213+
int log_level = pt.get("log.level", (int) loguru::Verbosity_INFO);
210214
if (log_level < -3 || log_level > 9)
211215
throw std::runtime_error("Invalid log.level (valid range: -3 to 9");
212216

@@ -228,16 +232,14 @@ void api_config::load_from_file(const std::string &filename) {
228232
}
229233
}
230234

235+
static std::once_flag api_config_once_flag;
236+
231237
const api_config *api_config::get_instance() {
232-
lslboost::call_once(&called_once, once_flag);
238+
std::call_once(api_config_once_flag, []() { api_config::get_instance_internal(); });
233239
return get_instance_internal();
234240
}
235241

236242
api_config *api_config::get_instance_internal() {
237243
static api_config cfg;
238244
return &cfg;
239245
}
240-
241-
void api_config::called_once() { get_instance_internal(); }
242-
243-
lslboost::once_flag api_config::once_flag = BOOST_ONCE_INIT;

src/api_config.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
#include <vector>
66

77
#include "common.h"
8-
namespace lslboost {
9-
struct once_flag;
10-
}
118

129
namespace lsl {
1310
/**
@@ -194,10 +191,8 @@ class api_config {
194191
api_config &operator=(const api_config &rhs) = delete;
195192

196193
private:
197-
// Thread-safe initialization logic (boilerplate).
198-
static lslboost::once_flag once_flag;
194+
/// Get the api_config singleton after thread-safe initialization if needed
199195
static api_config *get_instance_internal();
200-
static void called_once();
201196

202197
/**
203198
* Constructor.

src/buildinfo.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
extern "C" {
2+
#include "../include/lsl/common.h"
3+
4+
LIBLSL_C_API const char *lsl_library_info(void) {
5+
#ifdef LSL_LIBRARY_INFO_STR
6+
return LSL_LIBRARY_INFO_STR;
7+
#else
8+
return "Unknown (not set by build system)";
9+
#endif
10+
}
11+
}

src/cancellable_streambuf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class cancellable_streambuf : public std::streambuf,
6565
*/
6666
void cancel() {
6767
cancel_issued_ = true;
68-
lslboost::lock_guard<lslboost::recursive_mutex> lock(cancel_mut_);
68+
std::lock_guard<std::recursive_mutex> lock(cancel_mut_);
6969
cancel_started_ = false;
7070
this->get_service().get_io_context().post([this]() { close_if_open(); });
7171
}
@@ -80,7 +80,7 @@ class cancellable_streambuf : public std::streambuf,
8080
*/
8181
cancellable_streambuf *connect(const Protocol::endpoint &endpoint) {
8282
{
83-
lslboost::lock_guard<lslboost::recursive_mutex> lock(cancel_mut_);
83+
std::lock_guard<std::recursive_mutex> lock(cancel_mut_);
8484
if (cancel_issued_)
8585
throw std::runtime_error(
8686
"Attempt to connect() a cancellable_streambuf after it has been cancelled.");
@@ -130,7 +130,7 @@ class cancellable_streambuf : public std::streambuf,
130130
/// This function makes sure that a cancellation, if issued, is not being eaten by the
131131
/// io_context reset()
132132
void protected_reset() {
133-
lslboost::lock_guard<lslboost::recursive_mutex> lock(cancel_mut_);
133+
std::lock_guard<std::recursive_mutex> lock(cancel_mut_);
134134
// if the cancel() comes between completion of a run_one() and this call, close will be
135135
// issued right here at the next opportunity
136136
if (cancel_issued_) close_if_open();
@@ -224,7 +224,7 @@ class cancellable_streambuf : public std::streambuf,
224224
std::size_t bytes_transferred_;
225225
bool cancel_issued_;
226226
bool cancel_started_;
227-
lslboost::recursive_mutex cancel_mut_;
227+
std::recursive_mutex cancel_mut_;
228228
};
229229
} // namespace lsl
230230

src/cancellation.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#ifndef CANCELLATION_H
22
#define CANCELLATION_H
33

4-
#include <boost/thread/lock_guard.hpp>
5-
#include <boost/thread/recursive_mutex.hpp>
4+
#include <mutex>
65
#include <set>
76

87
namespace lsl {
@@ -30,22 +29,22 @@ class cancellable_registry {
3029

3130
/// Register a cancellable object.
3231
void register_cancellable(class cancellable_obj *o) {
33-
lslboost::lock_guard<lslboost::recursive_mutex> lock(state_mut_);
32+
std::lock_guard<std::recursive_mutex> lock(state_mut_);
3433
if (shutdown_issued_)
3534
throw shutdown_error(
3635
"The registry has begun to shut down; no new registrations possible.");
3736
cancellables_.insert(o);
3837
}
3938
/// Unregister a cancellable object.
4039
void unregister_cancellable(class cancellable_obj *o) {
41-
lslboost::lock_guard<lslboost::recursive_mutex> lock(state_mut_);
40+
std::lock_guard<std::recursive_mutex> lock(state_mut_);
4241
cancellables_.erase(o);
4342
}
4443

4544
bool shutdown_issued_{false}; // whether a shutdown has been issued
4645
std::set<cancellable_obj *>
4746
cancellables_; // a set of objects that we have to cancel upon re-resolves & disengage
48-
lslboost::recursive_mutex state_mut_; // mutex to protect the registry's state
47+
std::recursive_mutex state_mut_; // mutex to protect the registry's state
4948
};
5049

5150

@@ -77,15 +76,15 @@ class cancellable_obj {
7776

7877
/// Cancel all registered objects.
7978
inline void cancellable_registry::cancel_all_registered() {
80-
lslboost::lock_guard<lslboost::recursive_mutex> lock(state_mut_);
79+
std::lock_guard<std::recursive_mutex> lock(state_mut_);
8180
std::set<cancellable_obj *> copy(cancellables_);
8281
for (auto obj : copy)
8382
if (cancellables_.find(obj) != cancellables_.end()) obj->cancel();
8483
}
8584

8685
/// Cancel and prevent future object registrations.
8786
inline void cancellable_registry::cancel_and_shutdown() {
88-
lslboost::lock_guard<lslboost::recursive_mutex> lock(state_mut_);
87+
std::lock_guard<std::recursive_mutex> lock(state_mut_);
8988
shutdown_issued_ = true;
9089
cancel_all_registered();
9190
}

src/common.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,6 @@ LIBLSL_C_API int32_t lsl_protocol_version() {
2020

2121
LIBLSL_C_API int32_t lsl_library_version() { return LSL_LIBRARY_VERSION; }
2222

23-
LIBLSL_C_API const char *lsl_library_info() {
24-
#ifdef LSL_LIBRARY_INFO_STR
25-
return LSL_LIBRARY_INFO_STR;
26-
#else
27-
return "Unknown (not set by build system)";
28-
#endif
29-
}
30-
3123
LIBLSL_C_API double lsl_local_clock() {
3224
return lslboost::chrono::nanoseconds(
3325
lslboost::chrono::high_resolution_clock::now().time_since_epoch())
@@ -49,7 +41,7 @@ void lsl::ensure_lsl_initialized() {
4941
if (!is_initialized) {
5042
is_initialized = true;
5143

52-
loguru::g_stderr_verbosity = loguru::Verbosity_WARNING;
44+
loguru::g_stderr_verbosity = loguru::Verbosity_INFO;
5345
#ifdef LOGURU_DEBUG_LOGGING
5446
// Initialize loguru, mainly to print stacktraces on segmentation faults
5547
int argc = 1;

src/data_receiver.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ data_receiver::~data_receiver() {
4444

4545
void data_receiver::open_stream(double timeout) {
4646
closing_stream_ = false;
47-
lslboost::unique_lock<lslboost::mutex> lock(connected_mut_);
47+
std::unique_lock<std::mutex> lock(connected_mut_);
4848
auto connection_completed = [this]() { return connected_ || conn_.lost(); };
4949
if (!connection_completed()) {
5050
// start thread if not yet running
@@ -56,7 +56,7 @@ void data_receiver::open_stream(double timeout) {
5656
if (timeout >= FOREVER)
5757
connected_upd_.wait(lock, connection_completed);
5858
else if (!connected_upd_.wait_for(
59-
lock, lslboost::chrono::duration<double>(timeout), connection_completed))
59+
lock, std::chrono::duration<double>(timeout), connection_completed))
6060
throw timeout_error("The open_stream() operation timed out.");
6161
}
6262
if (conn_.lost())
@@ -71,7 +71,7 @@ void data_receiver::close_stream() {
7171
}
7272

7373
template <class T>
74-
double data_receiver::pull_sample_typed(T *buffer, int buffer_elements, double timeout) {
74+
double data_receiver::pull_sample_typed(T *buffer, uint32_t buffer_elements, double timeout) {
7575
if (conn_.lost())
7676
throw lost_error("The stream read by this outlet has been lost. To recover, you need to "
7777
"re-resolve the source and re-create the inlet.");
@@ -95,13 +95,13 @@ double data_receiver::pull_sample_typed(T *buffer, int buffer_elements, double t
9595
}
9696
}
9797

98-
template double data_receiver::pull_sample_typed<char>(char *, int, double);
99-
template double data_receiver::pull_sample_typed<int16_t>(int16_t *, int, double);
100-
template double data_receiver::pull_sample_typed<int32_t>(int32_t *, int, double);
101-
template double data_receiver::pull_sample_typed<int64_t>(int64_t *, int, double);
102-
template double data_receiver::pull_sample_typed<float>(float *, int, double);
103-
template double data_receiver::pull_sample_typed<double>(double *, int, double);
104-
template double data_receiver::pull_sample_typed<std::string>(std::string *, int, double);
98+
template double data_receiver::pull_sample_typed<char>(char *, uint32_t, double);
99+
template double data_receiver::pull_sample_typed<int16_t>(int16_t *, uint32_t, double);
100+
template double data_receiver::pull_sample_typed<int32_t>(int32_t *, uint32_t, double);
101+
template double data_receiver::pull_sample_typed<int64_t>(int64_t *, uint32_t, double);
102+
template double data_receiver::pull_sample_typed<float>(float *, uint32_t, double);
103+
template double data_receiver::pull_sample_typed<double>(double *, uint32_t, double);
104+
template double data_receiver::pull_sample_typed<std::string>(std::string *, uint32_t, double);
105105

106106
double data_receiver::pull_sample_untyped(void *buffer, int buffer_bytes, double timeout) {
107107
if (conn_.lost())
@@ -296,7 +296,7 @@ void data_receiver::data_thread() {
296296
// been successful, so we're now connected (and remain to be even if we later
297297
// recover silently)
298298
{
299-
lslboost::lock_guard<lslboost::mutex> lock(connected_mut_);
299+
std::lock_guard<std::mutex> lock(connected_mut_);
300300
connected_ = true;
301301
}
302302
connected_upd_.notify_all();

0 commit comments

Comments
 (0)