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_COMPARE_EXCHANGE_WEAK atomic_compare_exchange_weak
-
ATOMIC _Atomic
-
TYPEDEF_MUTEX
-
TYPEDEF_SPINLOCK
-
TYPEDEF_CONDVAR
-
TYPEDEF_RWLOCK
-
TYPEDEF_GLOBALCONTEXT
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.
-
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 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