inline void readlock() const { unsigned me = atomic_xadd(&l.u, (1<<16)); unsigned char val = me >> 16; while (val != l.s.read) sched_yield(); l.s.read++; }
inline void writelock() const { unsigned me = atomic_xadd(&l.u, (1<<16)); unsigned char val = (unsigned char)(me >> 16); while (val != l.s.write) sched_yield(); writing = true; }
inline void readlock() const { unsigned me = atomic_xadd(&l.u, (1<<16)); unsigned char val = (unsigned char)(me >> 16); while (val != l.s.read) asm volatile("pause\n": : :"memory"); l.s.read++; }
void auto_dir::reset(::DIR *p) { reset(); if (p) { #ifndef NDEBUG atomic_xadd(dir_constr_count, 1); #endif ptr = p; } }
void auto_dir::reset() { if (ptr) { #ifndef NDEBUG atomic_xadd(dir_destr_count, 1); #endif ::closedir(ptr); ptr = 0; } }
void rwlock_wrlock(rwlock_t *l) { #ifndef _WIN32 unsigned me = atomic_xadd(&l->u, (1<<16)); unsigned char val = me >> 16; while (val != l->s.write) cpu_relax(); #else AcquireSRWLockExclusive(l); #endif }
void rwlock_rdlock(rwlock_t *l) { #ifndef _WIN32 unsigned me = atomic_xadd(&l->u, (1<<16)); unsigned char val = me >> 16; while (val != l->s.read) cpu_relax(); l->s.read++; #else AcquireSRWLockShared(l); #endif }
static INLINE int DEC_ATOMIC(volatile int* val) { return atomic_xadd(val, -1); }