Skip to content

Instantly share code, notes, and snippets.

@ppLorins
Created May 10, 2018 13:26
Show Gist options
  • Save ppLorins/f23e8ecd7e69e4d9a20d0175d6420ba6 to your computer and use it in GitHub Desktop.
Save ppLorins/f23e8ecd7e69e4d9a20d0175d6420ba6 to your computer and use it in GitHub Desktop.
boost::shared_mutex
class upgrade_mutex
{
typedef boost::mutex mutex_t;
typedef boost::condition_variable cond_t;
typedef unsigned count_t;
mutex_t mut_;
cond_t gate1_;
cond_t gate2_;
count_t state_;
static const unsigned write_entered_ = 1U << (sizeof(count_t)*CHAR_BIT - 1);
static const unsigned upgradable_entered_ = write_entered_ >> 1;
static const unsigned n_readers_ = ~(write_entered_ | upgradable_entered_);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment