mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
Change mutex lock model to avoid dead lock and ensure locks are always released.
Additional cosmetic fixes: move 'name' as protected remove unnecessary local var Fix debug log
This commit is contained in:
parent
4c0545cc41
commit
da5de484f2
5 changed files with 202 additions and 385 deletions
|
@ -78,8 +78,10 @@ namespace hw {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class device {
|
class device {
|
||||||
|
protected:
|
||||||
|
std::string name;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
device() {}
|
device() {}
|
||||||
|
@ -92,8 +94,6 @@ namespace hw {
|
||||||
static const int SIGNATURE_FAKE = 1;
|
static const int SIGNATURE_FAKE = 1;
|
||||||
|
|
||||||
|
|
||||||
std::string name;
|
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* SETUP/TEARDOWN */
|
/* SETUP/TEARDOWN */
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
@ -104,7 +104,15 @@ namespace hw {
|
||||||
virtual bool release() = 0;
|
virtual bool release() = 0;
|
||||||
|
|
||||||
virtual bool connect(void) = 0;
|
virtual bool connect(void) = 0;
|
||||||
virtual bool disconnect() = 0;
|
virtual bool disconnect(void) = 0;
|
||||||
|
|
||||||
|
/* ======================================================================= */
|
||||||
|
/* LOCKER */
|
||||||
|
/* ======================================================================= */
|
||||||
|
virtual void lock(void) = 0;
|
||||||
|
virtual void unlock(void) = 0;
|
||||||
|
virtual bool try_lock(void) = 0;
|
||||||
|
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* WALLET & ADDRESS */
|
/* WALLET & ADDRESS */
|
||||||
|
|
|
@ -81,6 +81,17 @@ namespace hw {
|
||||||
dfns();
|
dfns();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ======================================================================= */
|
||||||
|
/* LOCKER */
|
||||||
|
/* ======================================================================= */
|
||||||
|
|
||||||
|
void device_default::lock() { }
|
||||||
|
|
||||||
|
bool device_default::try_lock() { return true; }
|
||||||
|
|
||||||
|
void device_default::unlock() { }
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* WALLET & ADDRESS */
|
/* WALLET & ADDRESS */
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
|
@ -59,6 +59,13 @@ namespace hw {
|
||||||
bool connect(void) override;
|
bool connect(void) override;
|
||||||
bool disconnect() override;
|
bool disconnect() override;
|
||||||
|
|
||||||
|
/* ======================================================================= */
|
||||||
|
/* LOCKER */
|
||||||
|
/* ======================================================================= */
|
||||||
|
void lock(void) override;
|
||||||
|
void unlock(void) override;
|
||||||
|
bool try_lock(void) override;
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* WALLET & ADDRESS */
|
/* WALLET & ADDRESS */
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -36,7 +36,8 @@
|
||||||
#include "device.hpp"
|
#include "device.hpp"
|
||||||
#include <PCSC/winscard.h>
|
#include <PCSC/winscard.h>
|
||||||
#include <PCSC/wintypes.h>
|
#include <PCSC/wintypes.h>
|
||||||
|
#include <boost/thread/mutex.hpp>
|
||||||
|
#include <boost/thread/recursive_mutex.hpp>
|
||||||
|
|
||||||
namespace hw {
|
namespace hw {
|
||||||
|
|
||||||
|
@ -80,13 +81,11 @@ namespace hw {
|
||||||
|
|
||||||
class device_ledger : public hw::device {
|
class device_ledger : public hw::device {
|
||||||
private:
|
private:
|
||||||
mutable std::mutex device_locker;
|
// Locker for concurrent access
|
||||||
mutable std::mutex tx_locker;
|
mutable boost::recursive_mutex device_locker;
|
||||||
void lock_device() ;
|
mutable boost::mutex command_locker;
|
||||||
void unlock_device() ;
|
|
||||||
void lock_tx() ;
|
|
||||||
void unlock_tx() ;
|
|
||||||
|
|
||||||
|
//PCSC management
|
||||||
std::string full_name;
|
std::string full_name;
|
||||||
SCARDCONTEXT hContext;
|
SCARDCONTEXT hContext;
|
||||||
SCARDHANDLE hCard;
|
SCARDHANDLE hCard;
|
||||||
|
@ -130,6 +129,14 @@ namespace hw {
|
||||||
bool connect(void) override;
|
bool connect(void) override;
|
||||||
bool disconnect() override;
|
bool disconnect() override;
|
||||||
|
|
||||||
|
|
||||||
|
/* ======================================================================= */
|
||||||
|
/* LOCKER */
|
||||||
|
/* ======================================================================= */
|
||||||
|
void lock(void) override;
|
||||||
|
void unlock(void) override;
|
||||||
|
bool try_lock(void) override;
|
||||||
|
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
/* WALLET & ADDRESS */
|
/* WALLET & ADDRESS */
|
||||||
/* ======================================================================= */
|
/* ======================================================================= */
|
||||||
|
|
Loading…
Reference in a new issue