smp.h

Include dependency graph for smp.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "2" [label="stdbool.h" tooltip="stdbool.h"]
    "1" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/smp.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/smp.h" fillcolor="#BFBFBF"]
    "1" -> "2" [dir=forward tooltip="include"]
}

This graph shows which files directly or indirectly include smp.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "7" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.c"]
    "48" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/dictionary.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/dictionary.c"]
    "6" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/bif.h"]
    "30" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h"]
    "18" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c"]
    "49" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/posix_nifs.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/posix_nifs.h"]
    "47" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/defaultatoms.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/defaultatoms.c"]
    "50" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/synclist.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/synclist.h"]
    "46" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/defaultatoms.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/defaultatoms.h"]
    "24" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.c"]
    "51" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/valueshashtable.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/valueshashtable.c"]
    "23" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.h"]
    "13" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/scheduler.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/scheduler.c"]
    "41" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/scheduler.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/scheduler.h"]
    "4" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.c"]
    "5" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/context.h"]
    "39" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/port.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/port.c"]
    "40" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/port.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/port.h"]
    "2" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/atom_table.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/atom_table.c"]
    "32" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.c"]
    "31" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.h"]
    "19" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/refc_binary.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/refc_binary.c"]
    "42" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/mailbox.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/mailbox.c"]
    "8" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.c"]
    "29" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.h"]
    "45" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/avmpack.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/avmpack.c"]
    "44" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/avmpack.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/avmpack.h"]
    "28" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/term.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/term.c"]
    "26" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.c"]
    "17" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c"]
    "22" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.h"]
    "38" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.h"]
    "20" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/resources.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/resources.c"]
    "27" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c"]
    "35" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_crypto.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_crypto.h"]
    "1" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/smp.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/smp.h" fillcolor="#BFBFBF"]
    "25" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.c"]
    "36" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.h"]
    "14" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/erl_nif_priv.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/erl_nif_priv.h"]
    "33" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/sys.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/sys.h"]
    "3" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/atomshashtable.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/atomshashtable.c"]
    "9" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/nifs.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/nifs.c"]
    "34" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/nifs.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/nifs.h"]
    "11" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/debug.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/debug.c"]
    "10" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/debug.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/debug.h"]
    "15" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/globalcontext.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/globalcontext.c"]
    "43" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/globalcontext.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/globalcontext.h"]
    "12" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/memory.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/memory.c"]
    "16" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.c"]
    "37" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.h"]
    "21" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/externalterm.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/externalterm.c"]
    "6" -> "7" [dir=back tooltip="include"]
    "6" -> "8" [dir=back tooltip="include"]
    "6" -> "9" [dir=back tooltip="include"]
    "30" -> "9" [dir=back tooltip="include"]
    "49" -> "15" [dir=back tooltip="include"]
    "49" -> "9" [dir=back tooltip="include"]
    "49" -> "16" [dir=back tooltip="include"]
    "49" -> "18" [dir=back tooltip="include"]
    "50" -> "4" [dir=back tooltip="include"]
    "50" -> "15" [dir=back tooltip="include"]
    "50" -> "43" [dir=back tooltip="include"]
    "50" -> "42" [dir=back tooltip="include"]
    "50" -> "9" [dir=back tooltip="include"]
    "46" -> "7" [dir=back tooltip="include"]
    "46" -> "47" [dir=back tooltip="include"]
    "46" -> "48" [dir=back tooltip="include"]
    "46" -> "15" [dir=back tooltip="include"]
    "46" -> "26" [dir=back tooltip="include"]
    "46" -> "9" [dir=back tooltip="include"]
    "46" -> "27" [dir=back tooltip="include"]
    "46" -> "25" [dir=back tooltip="include"]
    "46" -> "16" [dir=back tooltip="include"]
    "46" -> "17" [dir=back tooltip="include"]
    "46" -> "39" [dir=back tooltip="include"]
    "46" -> "40" [dir=back tooltip="include"]
    "46" -> "18" [dir=back tooltip="include"]
    "46" -> "20" [dir=back tooltip="include"]
    "46" -> "32" [dir=back tooltip="include"]
    "23" -> "24" [dir=back tooltip="include"]
    "23" -> "25" [dir=back tooltip="include"]
    "23" -> "16" [dir=back tooltip="include"]
    "23" -> "17" [dir=back tooltip="include"]
    "41" -> "15" [dir=back tooltip="include"]
    "41" -> "42" [dir=back tooltip="include"]
    "41" -> "9" [dir=back tooltip="include"]
    "41" -> "16" [dir=back tooltip="include"]
    "41" -> "13" [dir=back tooltip="include"]
    "5" -> "6" [dir=back tooltip="include"]
    "5" -> "4" [dir=back tooltip="include"]
    "5" -> "10" [dir=back tooltip="include"]
    "5" -> "14" [dir=back tooltip="include"]
    "5" -> "21" [dir=back tooltip="include"]
    "5" -> "15" [dir=back tooltip="include"]
    "5" -> "22" [dir=back tooltip="include"]
    "5" -> "12" [dir=back tooltip="include"]
    "5" -> "8" [dir=back tooltip="include"]
    "5" -> "29" [dir=back tooltip="include"]
    "5" -> "9" [dir=back tooltip="include"]
    "5" -> "34" [dir=back tooltip="include"]
    "5" -> "27" [dir=back tooltip="include"]
    "5" -> "25" [dir=back tooltip="include"]
    "5" -> "16" [dir=back tooltip="include"]
    "5" -> "17" [dir=back tooltip="include"]
    "5" -> "39" [dir=back tooltip="include"]
    "5" -> "40" [dir=back tooltip="include"]
    "5" -> "19" [dir=back tooltip="include"]
    "5" -> "20" [dir=back tooltip="include"]
    "5" -> "41" [dir=back tooltip="include"]
    "5" -> "31" [dir=back tooltip="include"]
    "5" -> "28" [dir=back tooltip="include"]
    "40" -> "24" [dir=back tooltip="include"]
    "40" -> "9" [dir=back tooltip="include"]
    "40" -> "25" [dir=back tooltip="include"]
    "40" -> "16" [dir=back tooltip="include"]
    "40" -> "17" [dir=back tooltip="include"]
    "40" -> "39" [dir=back tooltip="include"]
    "31" -> "32" [dir=back tooltip="include"]
    "29" -> "6" [dir=back tooltip="include"]
    "29" -> "8" [dir=back tooltip="include"]
    "29" -> "9" [dir=back tooltip="include"]
    "29" -> "30" [dir=back tooltip="include"]
    "29" -> "31" [dir=back tooltip="include"]
    "29" -> "33" [dir=back tooltip="include"]
    "44" -> "45" [dir=back tooltip="include"]
    "44" -> "15" [dir=back tooltip="include"]
    "44" -> "9" [dir=back tooltip="include"]
    "22" -> "23" [dir=back tooltip="include"]
    "22" -> "26" [dir=back tooltip="include"]
    "22" -> "9" [dir=back tooltip="include"]
    "22" -> "27" [dir=back tooltip="include"]
    "22" -> "25" [dir=back tooltip="include"]
    "22" -> "16" [dir=back tooltip="include"]
    "22" -> "17" [dir=back tooltip="include"]
    "22" -> "18" [dir=back tooltip="include"]
    "22" -> "28" [dir=back tooltip="include"]
    "38" -> "17" [dir=back tooltip="include"]
    "35" -> "27" [dir=back tooltip="include"]
    "1" -> "2" [dir=back tooltip="include"]
    "1" -> "3" [dir=back tooltip="include"]
    "1" -> "4" [dir=back tooltip="include"]
    "1" -> "5" [dir=back tooltip="include"]
    "1" -> "15" [dir=back tooltip="include"]
    "1" -> "43" [dir=back tooltip="include"]
    "1" -> "8" [dir=back tooltip="include"]
    "1" -> "9" [dir=back tooltip="include"]
    "1" -> "13" [dir=back tooltip="include"]
    "1" -> "50" [dir=back tooltip="include"]
    "1" -> "51" [dir=back tooltip="include"]
    "36" -> "25" [dir=back tooltip="include"]
    "14" -> "4" [dir=back tooltip="include"]
    "14" -> "15" [dir=back tooltip="include"]
    "14" -> "12" [dir=back tooltip="include"]
    "14" -> "16" [dir=back tooltip="include"]
    "14" -> "17" [dir=back tooltip="include"]
    "14" -> "18" [dir=back tooltip="include"]
    "14" -> "19" [dir=back tooltip="include"]
    "14" -> "20" [dir=back tooltip="include"]
    "33" -> "4" [dir=back tooltip="include"]
    "33" -> "15" [dir=back tooltip="include"]
    "33" -> "8" [dir=back tooltip="include"]
    "33" -> "9" [dir=back tooltip="include"]
    "33" -> "16" [dir=back tooltip="include"]
    "33" -> "20" [dir=back tooltip="include"]
    "33" -> "13" [dir=back tooltip="include"]
    "34" -> "8" [dir=back tooltip="include"]
    "34" -> "9" [dir=back tooltip="include"]
    "34" -> "27" [dir=back tooltip="include"]
    "34" -> "35" [dir=back tooltip="include"]
    "34" -> "25" [dir=back tooltip="include"]
    "34" -> "36" [dir=back tooltip="include"]
    "34" -> "16" [dir=back tooltip="include"]
    "34" -> "37" [dir=back tooltip="include"]
    "34" -> "17" [dir=back tooltip="include"]
    "34" -> "38" [dir=back tooltip="include"]
    "34" -> "18" [dir=back tooltip="include"]
    "10" -> "11" [dir=back tooltip="include"]
    "10" -> "12" [dir=back tooltip="include"]
    "10" -> "13" [dir=back tooltip="include"]
    "43" -> "44" [dir=back tooltip="include"]
    "43" -> "4" [dir=back tooltip="include"]
    "43" -> "5" [dir=back tooltip="include"]
    "43" -> "46" [dir=back tooltip="include"]
    "43" -> "15" [dir=back tooltip="include"]
    "43" -> "12" [dir=back tooltip="include"]
    "43" -> "8" [dir=back tooltip="include"]
    "43" -> "29" [dir=back tooltip="include"]
    "43" -> "9" [dir=back tooltip="include"]
    "43" -> "27" [dir=back tooltip="include"]
    "43" -> "25" [dir=back tooltip="include"]
    "43" -> "36" [dir=back tooltip="include"]
    "43" -> "16" [dir=back tooltip="include"]
    "43" -> "37" [dir=back tooltip="include"]
    "43" -> "17" [dir=back tooltip="include"]
    "43" -> "38" [dir=back tooltip="include"]
    "43" -> "39" [dir=back tooltip="include"]
    "43" -> "40" [dir=back tooltip="include"]
    "43" -> "18" [dir=back tooltip="include"]
    "43" -> "49" [dir=back tooltip="include"]
    "43" -> "41" [dir=back tooltip="include"]
    "43" -> "32" [dir=back tooltip="include"]
    "43" -> "33" [dir=back tooltip="include"]
    "37" -> "16" [dir=back tooltip="include"]
    "37" -> "17" [dir=back tooltip="include"]
}

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)

Typedefs

typedef struct Mutex Mutex
typedef struct SpinLock SpinLock
typedef struct CondVar CondVar
typedef struct RWLock RWLock
typedef struct GlobalContext GlobalContext

Functions

Mutex *smp_mutex_create()

Create a new mutex.

Returns:

a pointer to a mutex.

void smp_mutex_destroy(Mutex *mtx)

Destroy a mutex.

Parameters:
  • mtx – the mutex to destroy

void smp_mutex_lock(Mutex *mtx)

Lock a mutex.

Parameters:
  • mtx – the mutex to lock

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_mutex_unlock(Mutex *mtx)

Unlock a mutex.

Parameters:
  • mtx – the mutex to unlock

CondVar *smp_condvar_create()

Create a new condition variable.

Returns:

a pointer to a cv.

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_destroy(RWLock *lock)

Destroy a rwlock.

Parameters:
  • lock – the lock to destroy

void smp_rwlock_rdlock(RWLock *lock)

Read lock a rwlock.

Parameters:
  • lock – the lock to read 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

void smp_rwlock_unlock(RWLock *lock)

Unlock a rwlock.

Parameters:
  • lock – the lock to unlock

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