Skip to content

Instantly share code, notes, and snippets.

@jmgao
Created February 20, 2019 02:56
Show Gist options
  • Save jmgao/173ba47348ed61f447fb3ab0c340c28f to your computer and use it in GitHub Desktop.
Save jmgao/173ba47348ed61f447fb3ab0c340c28f to your computer and use it in GitHub Desktop.
class AutoMutex {
public:
inline AutoMutex() : mLockCount(0) {
int expected = 0;
__c11_atomic_compare_exchange_weak(&mLockCount, &expected, expected + 1,
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
}
private:
char x[128];
_Atomic(int) mLockCount;
};
void flush(void) {
AutoMutex mtx;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment