Name

SPVM::Document::NativeAPI::Mutex - Mutex Native APIs

Description

The mutex native APIs in SPVM are the APIs for mutex.

Usage

SPVM_API_MUTEX* api_mutex = env->api->mutex;

void* mutex = api_mutex->new_instance();

api_mutex->lock(env, stack, mutex);

api_mutex->unlock(env, stack, mutex);

api_mutex->free_instance(mutex);

Details

These APIs implements read-write locks in Linux/UNIX and slim reader/writer (SRW) locks in Windows.

Native APIs

new_instance

void* (*new_instance)(SPVM_ENV* env, SPVM_VALUE* stack);

Creates a new mutex and initialize it, and returns it.

free_instance

void (*free_instance)(SPVM_ENV* env, SPVM_VALUE* stack, void* mutex);

Destroys the mutex mutex and frees it.

lock

void (*lock)(SPVM_ENV* env, SPVM_VALUE* stack, void* mutex);

Locks the mutex mutex.

Calls the pthread_rwlock_wrlock function in Linux/UNIX.

Calls the AcquireSRWLockExclusive function in Windows.

unlock

void (*unlock)(SPVM_ENV* env, SPVM_VALUE* stack, void* mutex);

Unlocks the mutex mutex.

Calls the pthread_rwlock_unlock function in Linux/UNIX.

Calls the ReleaseSRWLockExclusive function in Windows.

reader_lock

void (*reader_lock)(SPVM_ENV* env, SPVM_VALUE* stack, void* mutex);

Locks the mutex mutex for reading.

Calls the pthread_rwlock_rdlock function in Linux/UNIX.

Calls the AcquireSRWLockShared function in Windows.

reader_unlock

void (*reader_unlock)(SPVM_ENV* env, SPVM_VALUE* stack, void* mutex);

Unlocks the mutex mutex for reading.

Calls the pthread_rwlock_unlock function in Linux/UNIX.

Calls the ReleaseSRWLockShared function in Windows.

Native API IDs

0 new_instance
1 free_instance
2 lock
3 unlock
4 reader_lock
5 reader_unlock

See Also

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License