I have need of a semaphore, but I have been unable to find any good ones on the web, only some source.
So I modified the source to roll out my own simplistic semaphore, and thus I'd like for some other people to look it over and see that I haven't done something stupid.
If you know of a good (and fast!) semaphore out there already, I'd also be interested.
//The current semaphore count.
tbb::atomic<unsigned int> m_count;
//mutex_ protects count_.
//Any code that reads or writes the count_ data must hold a lock on
//Code that increments count_ must notify the condition variable.
explicit XSemaphore(unsigned int initial_count)
m_count = initial_count;
unsigned int get_count() const //for debugging/testing only
//The "lock" object locks the mutex when it's constructed,
//and unlocks it when it's destroyed.
void signal() //called "release" in Java
//Wake up any waiting threads.
//Always do this, even if count_ wasn't 0 on entry.
//Otherwise, we might not wake up enough waiting threads if we
//get a number of signal() calls in a row.
void wait() //called "acquire" in Java
while (m_count == 0)