smp.h
Include dependency graph for smp.h:
This graph shows which files directly or indirectly include smp.h:
Multicore support functions.
This header defines multicore support functions to be implemented for SMP builds.
Defines
-
CLANG_THREAD_SANITIZE_SAFE
-
ATOMIC
-
TYPEDEF_MUTEX
-
TYPEDEF_SPINLOCK
-
TYPEDEF_CONDVAR
-
TYPEDEF_RWLOCK
-
TYPEDEF_GLOBALCONTEXT
-
SMP_SPINLOCK_LOCK(spinlock) smp_spinlock_lock(spinlock)
-
SMP_SPINLOCK_TRYLOCK(spinlock) smp_spinlock_trylock(spinlock)
-
SMP_SPINLOCK_UNLOCK(spinlock) smp_spinlock_unlock(spinlock)
-
SMP_MUTEX_LOCK(mutex) smp_mutex_lock(mutex)
-
SMP_MUTEX_TRYLOCK(mutex) smp_mutex_trylock(mutex)
-
SMP_MUTEX_UNLOCK(mutex) smp_mutex_unlock(mutex)
-
SMP_RWLOCK_RDLOCK(lock) smp_rwlock_rdlock(lock)
-
SMP_RWLOCK_TRYRDLOCK(lock) smp_rwlock_tryrdlock(lock)
-
SMP_RWLOCK_WRLOCK(lock) smp_rwlock_wrlock(lock)
-
SMP_RWLOCK_UNLOCK(lock) smp_rwlock_unlock(lock)
Functions
-
bool smp_mutex_trylock(Mutex *mtx)
Try and lock a mutex.
- Parameters:
mtx – the mutex to lock
- Returns:
true
if the mutex was acquired.
-
void smp_condvar_destroy(CondVar *cv)
Destroy a condition variable.
- Parameters:
cv – variable to destroy.
-
void smp_condvar_wait(CondVar *cv, Mutex *mtx)
Wait on a condition variable, atomically unlocking the mutex.
- Parameters:
cv – variable to wait on.
mtx – mutex to unlock/lock.
-
void smp_condvar_signal(CondVar *cv)
Signal a single thread waiting on a condition variable.
- Parameters:
cv – variable to signal.
-
RWLock *smp_rwlock_create()
Create a new rwlock.
A RW Lock can be replaced by a mutex if RW Lock are not available on the platform.
- Returns:
a pointer to a lock.
-
bool smp_rwlock_tryrdlock(RWLock *lock)
Try to acquire read lock of a rwlock.
- Parameters:
lock – the lock to read lock
- Returns:
true
if lock was acquired
-
void smp_rwlock_wrlock(RWLock *lock)
Write lock a rwlock.
- Parameters:
lock – the lock to write lock
-
static inline void smp_spinlock_init(SpinLock *lock)
Initialize a spinlock based on atomics.
- Parameters:
lock – the spin lock to initialize
-
static inline void smp_spinlock_lock(SpinLock *lock)
Lock a spinlock.
- Parameters:
lock – the spin lock to lock
-
static inline bool smp_spinlock_trylock(SpinLock *lock)
Try to lock a spinlock.
- Parameters:
lock – the spin lock to lock
- Returns:
true if the spin lock was locked
-
static inline void smp_spinlock_unlock(SpinLock *lock)
Unlock a spinlock.
- Parameters:
lock – the spin lock to unlock
-
int smp_get_online_processors()
Get the number of online processors to configure schedulers.
This value is one plus the maximum number of times smp_scheduler_start will be called by the scheduler.
- Returns:
the number of online processors.
-
void smp_scheduler_start(GlobalContext *glb)
Start a new scheduler, calling
scheduler_entry_point
with the given global context.- Parameters:
glb – the global context
-
bool smp_is_main_thread(GlobalContext *glb)
Determine if caller is in the main thread, i.e. thread that was not started with acmsmp_scheduler_start.
-
struct SpinLock
- #include <smp.h>
Public Members
- int ATOMIC lock