Skip to content

Commit

Permalink
Change mutex lock model to avoid dead lock and ensure locks are alway…
Browse files Browse the repository at this point in the history
…s released.

Additional cosmetic fixes:
 move 'name' as protected
 remove unnecessary local var
 Fix debug log
  • Loading branch information
cslashm committed Mar 31, 2018
1 parent 641dfc9 commit 100b7bc
Show file tree
Hide file tree
Showing 5 changed files with 202 additions and 385 deletions.
16 changes: 12 additions & 4 deletions src/device/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ namespace hw {
return false;
}


class device {
protected:
std::string name;

public:

device() {}
Expand All @@ -92,8 +94,6 @@ namespace hw {
static const int SIGNATURE_FAKE = 1;


std::string name;

/* ======================================================================= */
/* SETUP/TEARDOWN */
/* ======================================================================= */
Expand All @@ -104,7 +104,15 @@ namespace hw {
virtual bool release() = 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 */
Expand Down
11 changes: 11 additions & 0 deletions src/device/device_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ namespace hw {
dfns();
}


/* ======================================================================= */
/* LOCKER */
/* ======================================================================= */

void device_default::lock() { }

bool device_default::try_lock() { return true; }

void device_default::unlock() { }

/* ======================================================================= */
/* WALLET & ADDRESS */
/* ======================================================================= */
Expand Down
7 changes: 7 additions & 0 deletions src/device/device_default.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ namespace hw {
bool connect(void) override;
bool disconnect() override;

/* ======================================================================= */
/* LOCKER */
/* ======================================================================= */
void lock(void) override;
void unlock(void) override;
bool try_lock(void) override;

/* ======================================================================= */
/* WALLET & ADDRESS */
/* ======================================================================= */
Expand Down
Loading

0 comments on commit 100b7bc

Please sign in to comment.