Skip to content

Commit

Permalink
device: boost -> std locks to fix c++17 compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
selsta committed Oct 26, 2023
1 parent 5965b02 commit 5136974
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
9 changes: 3 additions & 6 deletions src/device/device_ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
#include "cryptonote_basic/subaddress_index.h"
#include "cryptonote_core/cryptonote_tx_utils.h"

#include <boost/thread/locks.hpp>
#include <boost/thread/lock_guard.hpp>

namespace hw {

namespace ledger {
Expand Down Expand Up @@ -322,10 +319,10 @@ namespace hw {
//automatic lock one more level on device ensuring the current thread is allowed to use it
#define AUTO_LOCK_CMD() \
/* lock both mutexes without deadlock*/ \
boost::lock(device_locker, command_locker); \
std::lock(device_locker, command_locker); \
/* make sure both already-locked mutexes are unlocked at the end of scope */ \
boost::lock_guard<boost::recursive_mutex> lock1(device_locker, boost::adopt_lock); \
boost::lock_guard<boost::mutex> lock2(command_locker, boost::adopt_lock)
std::lock_guard<std::recursive_mutex> lock1(device_locker, std::adopt_lock); \
std::lock_guard<std::mutex> lock2(command_locker, std::adopt_lock)

//lock the device for a long sequence
void device_ledger::lock(void) {
Expand Down
7 changes: 3 additions & 4 deletions src/device/device_ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
#include "device.hpp"
#include "log.hpp"
#include "device_io_hid.hpp"
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include <mutex>

namespace hw {

Expand Down Expand Up @@ -140,8 +139,8 @@ namespace hw {
class device_ledger : public hw::device {
private:
// Locker for concurrent access
mutable boost::recursive_mutex device_locker;
mutable boost::mutex command_locker;
mutable std::recursive_mutex device_locker;
mutable std::mutex command_locker;

//IO
hw::io::device_io_hid hw_device;
Expand Down
15 changes: 7 additions & 8 deletions src/device_trezor/device_trezor_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@


#include <cstddef>
#include <mutex>
#include <string>
#include "device/device.hpp"
#include "device/device_default.hpp"
#include "device/device_cold.hpp"
#include <boost/scope_exit.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
#include "cryptonote_config.h"
#include "trezor.hpp"

Expand All @@ -49,12 +48,12 @@
//automatic lock one more level on device ensuring the current thread is allowed to use it
#define TREZOR_AUTO_LOCK_CMD() \
/* lock both mutexes without deadlock*/ \
boost::lock(device_locker, command_locker); \
std::lock(device_locker, command_locker); \
/* make sure both already-locked mutexes are unlocked at the end of scope */ \
boost::lock_guard<boost::recursive_mutex> lock1(device_locker, boost::adopt_lock); \
boost::lock_guard<boost::mutex> lock2(command_locker, boost::adopt_lock)
std::lock_guard<std::recursive_mutex> lock1(device_locker, std::adopt_lock); \
std::lock_guard<std::mutex> lock2(command_locker, std::adopt_lock)

#define TREZOR_AUTO_LOCK_DEVICE() boost::lock_guard<boost::recursive_mutex> lock1_device(device_locker)
#define TREZOR_AUTO_LOCK_DEVICE() std::lock_guard<std::recursive_mutex> lock1_device(device_locker)

namespace hw {
namespace trezor {
Expand Down Expand Up @@ -86,8 +85,8 @@ namespace trezor {
protected:

// Locker for concurrent access
mutable boost::recursive_mutex device_locker;
mutable boost::mutex command_locker;
mutable std::recursive_mutex device_locker;
mutable std::mutex command_locker;

std::shared_ptr<Transport> m_transport;
i_device_callback * m_callback;
Expand Down

0 comments on commit 5136974

Please sign in to comment.