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"]
    "46" [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"]
    "29" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/platform_nifs.h"]
    "17" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/posix_nifs.c"]
    "47" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/posix_nifs.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/posix_nifs.h"]
    "48" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/synclist.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/synclist.h"]
    "45" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/defaultatoms.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/defaultatoms.h"]
    "23" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.c"]
    "49" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/valueshashtable.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/valueshashtable.c"]
    "22" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/inet.h"]
    "40" [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"]
    "38" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/port.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/port.c"]
    "39" [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"]
    "31" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.c"]
    "30" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/stacktrace.h"]
    "18" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/refc_binary.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/refc_binary.c"]
    "41" [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"]
    "28" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/module.h"]
    "44" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/avmpack.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/avmpack.c"]
    "43" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/avmpack.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/avmpack.h"]
    "27" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/term.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/term.c"]
    "25" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.c"]
    "16" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.c"]
    "21" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/interop.h"]
    "37" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_ssl.h"]
    "19" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/resources.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/resources.c"]
    "26" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_crypto.c"]
    "34" [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"]
    "24" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.c"]
    "35" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_net.h"]
    "13" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/erl_nif_priv.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/erl_nif_priv.h"]
    "32" [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"]
    "33" [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"]
    "14" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/globalcontext.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/globalcontext.c"]
    "42" [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"]
    "15" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.c" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.c"]
    "36" [label="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.h" tooltip="/home/runner/work/AtomVM/AtomVM/src/libAtomVM/otp_socket.h"]
    "20" [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"]
    "29" -> "9" [dir=back tooltip="include"]
    "47" -> "14" [dir=back tooltip="include"]
    "47" -> "9" [dir=back tooltip="include"]
    "47" -> "15" [dir=back tooltip="include"]
    "47" -> "17" [dir=back tooltip="include"]
    "48" -> "4" [dir=back tooltip="include"]
    "48" -> "14" [dir=back tooltip="include"]
    "48" -> "42" [dir=back tooltip="include"]
    "48" -> "41" [dir=back tooltip="include"]
    "48" -> "9" [dir=back tooltip="include"]
    "45" -> "7" [dir=back tooltip="include"]
    "45" -> "46" [dir=back tooltip="include"]
    "45" -> "14" [dir=back tooltip="include"]
    "45" -> "25" [dir=back tooltip="include"]
    "45" -> "9" [dir=back tooltip="include"]
    "45" -> "26" [dir=back tooltip="include"]
    "45" -> "24" [dir=back tooltip="include"]
    "45" -> "15" [dir=back tooltip="include"]
    "45" -> "16" [dir=back tooltip="include"]
    "45" -> "38" [dir=back tooltip="include"]
    "45" -> "39" [dir=back tooltip="include"]
    "45" -> "17" [dir=back tooltip="include"]
    "45" -> "19" [dir=back tooltip="include"]
    "45" -> "31" [dir=back tooltip="include"]
    "22" -> "23" [dir=back tooltip="include"]
    "22" -> "24" [dir=back tooltip="include"]
    "22" -> "15" [dir=back tooltip="include"]
    "22" -> "16" [dir=back tooltip="include"]
    "40" -> "14" [dir=back tooltip="include"]
    "40" -> "41" [dir=back tooltip="include"]
    "40" -> "9" [dir=back tooltip="include"]
    "40" -> "15" [dir=back tooltip="include"]
    "5" -> "6" [dir=back tooltip="include"]
    "5" -> "4" [dir=back tooltip="include"]
    "5" -> "10" [dir=back tooltip="include"]
    "5" -> "13" [dir=back tooltip="include"]
    "5" -> "20" [dir=back tooltip="include"]
    "5" -> "14" [dir=back tooltip="include"]
    "5" -> "21" [dir=back tooltip="include"]
    "5" -> "12" [dir=back tooltip="include"]
    "5" -> "8" [dir=back tooltip="include"]
    "5" -> "28" [dir=back tooltip="include"]
    "5" -> "9" [dir=back tooltip="include"]
    "5" -> "33" [dir=back tooltip="include"]
    "5" -> "26" [dir=back tooltip="include"]
    "5" -> "24" [dir=back tooltip="include"]
    "5" -> "15" [dir=back tooltip="include"]
    "5" -> "16" [dir=back tooltip="include"]
    "5" -> "38" [dir=back tooltip="include"]
    "5" -> "39" [dir=back tooltip="include"]
    "5" -> "18" [dir=back tooltip="include"]
    "5" -> "19" [dir=back tooltip="include"]
    "5" -> "40" [dir=back tooltip="include"]
    "5" -> "30" [dir=back tooltip="include"]
    "5" -> "27" [dir=back tooltip="include"]
    "39" -> "23" [dir=back tooltip="include"]
    "39" -> "9" [dir=back tooltip="include"]
    "39" -> "24" [dir=back tooltip="include"]
    "39" -> "15" [dir=back tooltip="include"]
    "39" -> "16" [dir=back tooltip="include"]
    "39" -> "38" [dir=back tooltip="include"]
    "30" -> "31" [dir=back tooltip="include"]
    "28" -> "6" [dir=back tooltip="include"]
    "28" -> "8" [dir=back tooltip="include"]
    "28" -> "9" [dir=back tooltip="include"]
    "28" -> "29" [dir=back tooltip="include"]
    "28" -> "30" [dir=back tooltip="include"]
    "28" -> "32" [dir=back tooltip="include"]
    "28" -> "27" [dir=back tooltip="include"]
    "43" -> "44" [dir=back tooltip="include"]
    "43" -> "14" [dir=back tooltip="include"]
    "43" -> "9" [dir=back tooltip="include"]
    "21" -> "22" [dir=back tooltip="include"]
    "21" -> "25" [dir=back tooltip="include"]
    "21" -> "9" [dir=back tooltip="include"]
    "21" -> "26" [dir=back tooltip="include"]
    "21" -> "24" [dir=back tooltip="include"]
    "21" -> "15" [dir=back tooltip="include"]
    "21" -> "16" [dir=back tooltip="include"]
    "21" -> "17" [dir=back tooltip="include"]
    "21" -> "27" [dir=back tooltip="include"]
    "37" -> "16" [dir=back tooltip="include"]
    "34" -> "26" [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" -> "14" [dir=back tooltip="include"]
    "1" -> "42" [dir=back tooltip="include"]
    "1" -> "8" [dir=back tooltip="include"]
    "1" -> "9" [dir=back tooltip="include"]
    "1" -> "48" [dir=back tooltip="include"]
    "1" -> "49" [dir=back tooltip="include"]
    "35" -> "24" [dir=back tooltip="include"]
    "13" -> "4" [dir=back tooltip="include"]
    "13" -> "14" [dir=back tooltip="include"]
    "13" -> "12" [dir=back tooltip="include"]
    "13" -> "15" [dir=back tooltip="include"]
    "13" -> "16" [dir=back tooltip="include"]
    "13" -> "17" [dir=back tooltip="include"]
    "13" -> "18" [dir=back tooltip="include"]
    "13" -> "19" [dir=back tooltip="include"]
    "32" -> "4" [dir=back tooltip="include"]
    "32" -> "14" [dir=back tooltip="include"]
    "32" -> "8" [dir=back tooltip="include"]
    "32" -> "9" [dir=back tooltip="include"]
    "32" -> "15" [dir=back tooltip="include"]
    "32" -> "19" [dir=back tooltip="include"]
    "33" -> "8" [dir=back tooltip="include"]
    "33" -> "9" [dir=back tooltip="include"]
    "33" -> "26" [dir=back tooltip="include"]
    "33" -> "34" [dir=back tooltip="include"]
    "33" -> "24" [dir=back tooltip="include"]
    "33" -> "35" [dir=back tooltip="include"]
    "33" -> "15" [dir=back tooltip="include"]
    "33" -> "36" [dir=back tooltip="include"]
    "33" -> "16" [dir=back tooltip="include"]
    "33" -> "37" [dir=back tooltip="include"]
    "33" -> "17" [dir=back tooltip="include"]
    "10" -> "11" [dir=back tooltip="include"]
    "10" -> "12" [dir=back tooltip="include"]
    "42" -> "43" [dir=back tooltip="include"]
    "42" -> "4" [dir=back tooltip="include"]
    "42" -> "5" [dir=back tooltip="include"]
    "42" -> "45" [dir=back tooltip="include"]
    "42" -> "14" [dir=back tooltip="include"]
    "42" -> "12" [dir=back tooltip="include"]
    "42" -> "8" [dir=back tooltip="include"]
    "42" -> "28" [dir=back tooltip="include"]
    "42" -> "9" [dir=back tooltip="include"]
    "42" -> "26" [dir=back tooltip="include"]
    "42" -> "24" [dir=back tooltip="include"]
    "42" -> "35" [dir=back tooltip="include"]
    "42" -> "15" [dir=back tooltip="include"]
    "42" -> "36" [dir=back tooltip="include"]
    "42" -> "16" [dir=back tooltip="include"]
    "42" -> "37" [dir=back tooltip="include"]
    "42" -> "38" [dir=back tooltip="include"]
    "42" -> "39" [dir=back tooltip="include"]
    "42" -> "17" [dir=back tooltip="include"]
    "42" -> "47" [dir=back tooltip="include"]
    "42" -> "40" [dir=back tooltip="include"]
    "42" -> "31" [dir=back tooltip="include"]
    "42" -> "32" [dir=back tooltip="include"]
    "36" -> "15" [dir=back tooltip="include"]
    "36" -> "16" [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 lock