30 ThreadBlockerWhileUsedFast2

No longer used so the code is only recorded here in this web-page.

A specialised version that assumes Wait() is called exactly once, allowing for a more efficient implementation.

This is achieved by artificially keeping the counter nonzero until Wait() is called by offsetting the count by +1. This eliminates the zero transitions during normal operation.

class ThreadBlockerWhileUsedFast2
{
public:
    ThreadBlockerWhileUsedFast2(int count = 0) : blocker_(count+1) {}
    int operator++()
    {
        return ++blocker_ - 1;
    }
    int operator--()
    {
        return --blocker_ - 1;
    }
    int operator++(int) { return operator++()-1; }
    int operator--(int) { return operator--()+1; }

    void Wait()
    {
        operator--();
        blocker_.Wait();        
    }

private:
    ThreadBlockerWhileUsedFast blocker_;
};