futriix/src/fastlock.h

46 lines
762 B
C
Raw Normal View History

2019-02-10 20:24:11 -05:00
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
2019-02-10 22:00:19 -05:00
/* Begin C API */
struct fastlock;
2019-02-10 20:24:11 -05:00
void fastlock_init(struct fastlock *lock);
void fastlock_lock(struct fastlock *lock);
void fastlock_unlock(struct fastlock *lock);
void fastlock_free(struct fastlock *lock);
2019-02-10 22:00:19 -05:00
/* End C API */
2019-02-10 20:24:11 -05:00
#ifdef __cplusplus
}
2019-02-10 22:00:19 -05:00
#endif
struct fastlock
{
volatile unsigned m_active;
volatile unsigned m_avail;
2019-02-16 14:25:14 -05:00
volatile int m_pidOwner;
volatile int m_depth;
2019-02-10 22:00:19 -05:00
#ifdef __cplusplus
fastlock()
{
fastlock_init(this);
}
2019-02-10 22:00:19 -05:00
void lock()
{
fastlock_lock(this);
}
void unlock()
{
fastlock_unlock(this);
}
2019-02-18 22:25:35 -05:00
bool fOwnLock(); // true if this thread owns the lock, NOTE: not 100% reliable, use for debugging only
2019-02-10 22:00:19 -05:00
#endif
};