forked from sccn/liblsl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.cpp
More file actions
37 lines (33 loc) · 1.2 KB
/
common.cpp
File metadata and controls
37 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "common.h"
#include <boost/chrono/duration.hpp>
#include <boost/chrono/system_clocks.hpp>
#ifdef _WIN32
#include "api_config.h"
#include <windows.h>
#include <mmsystem.h>
#pragma comment (lib,"winmm.lib")
#endif
// === implementation of misc functions ===
/// Implementation of the clock facility.
double lsl::lsl_clock() {
return lslboost::chrono::nanoseconds(lslboost::chrono::high_resolution_clock::now().time_since_epoch()).count()/1000000000.0;
}
/// Ensure that LSL is initialized. Performs initialization tasks
void lsl::ensure_lsl_initialized() {
static bool is_initialized = false;
if (!is_initialized) {
is_initialized = true;
#ifdef _WIN32
// if a timer resolution other than 0 is requested (0 means don't override)...
if (int desired_timer_resolution = lsl::api_config::get_instance()->timer_resolution()) {
// then override it for the lifetime of this program
struct override_timer_resolution_until_exit {
override_timer_resolution_until_exit(int res): res_(res) { timeBeginPeriod(res_); }
~override_timer_resolution_until_exit() { timeEndPeriod(res_); }
int res_;
};
static override_timer_resolution_until_exit overrider(desired_timer_resolution);
}
#endif
}
}