diff options
author | Szczepan Zalega <szczepan@nitrokey.com> | 2017-01-11 16:10:30 +0100 |
---|---|---|
committer | Szczepan Zalega <szczepan@nitrokey.com> | 2017-03-11 15:41:36 +0100 |
commit | 2dec896b3f853d2e509c4eb15fe5dd6c28e0a1d7 (patch) | |
tree | 5a04ab0aa61e63f381d04a10619b46a3a065a724 /device.cc | |
parent | 774f3a0d93bac42aa50d4d30753e00f769b17881 (diff) | |
download | libnitrokey-2dec896b3f853d2e509c4eb15fe5dd6c28e0a1d7.tar.gz libnitrokey-2dec896b3f853d2e509c4eb15fe5dd6c28e0a1d7.tar.bz2 |
Use lock_guard while accessing hid_api
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'device.cc')
-rw-r--r-- | device.cc | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -6,6 +6,9 @@ #include "include/misc.h" #include "include/device.h" #include "include/log.h" +#include <mutex> + +std::mutex mex_dev_com; using namespace nitrokey::device; using namespace nitrokey::log; @@ -26,6 +29,7 @@ Device::Device(const uint16_t vid, const uint16_t pid, const DeviceModel model, {} bool Device::disconnect() { + std::lock_guard<std::mutex> lock(mex_dev_com); Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); if(mp_devhandle == nullptr) return false; @@ -35,6 +39,7 @@ bool Device::disconnect() { return true; } bool Device::connect() { + std::lock_guard<std::mutex> lock(mex_dev_com); Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); // hid_init(); // done automatically on hid_open @@ -43,6 +48,7 @@ bool Device::connect() { } int Device::send(const void *packet) { + std::lock_guard<std::mutex> lock(mex_dev_com); Log::instance()(__PRETTY_FUNCTION__, Loglevel::DEBUG_L2); if (mp_devhandle == NULL) @@ -53,6 +59,7 @@ int Device::send(const void *packet) { } int Device::recv(void *packet) { + std::lock_guard<std::mutex> lock(mex_dev_com); int status; int retry_count = 0; |