blib/lib/SPVM/Document/NativeAPI/Mutex.pm untested

filter: Statementstmt n/a Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a SCAR -
1 =head1 Name
2  
3 SPVM::Document::NativeAPI::Mutex - Mutex Native APIs
4  
5 =head1 Description
6  
7 The mutex native APIs in L<SPVM> are the APIs for mutex.
8  
9 =head1 Usage
10  
11 SPVM_API_MUTEX* api_mutex = env->api->mutex;
12
13 SPVM_NATIVE_MUTEX* mutex = api_mutex->new_instance(env, stack);
14
15 api_mutex->lock(env, stack, mutex);
16
17 api_mutex->unlock(env, stack, mutex);
18
19 api_mutex->free_instance(env, stack, mutex);
20  
21 =head1 Details
22  
23 These APIs implements read-write locks in Linux and UNIX and L<slim reader/writer (SRW) locks|https://learn.microsoft.com/en-us/windows/win32/sync/slim-reader-writer--srw--locks> in Windows.
24  
25 =head1 Native APIs
26  
27 =head2 new_instance
28  
29 C<SPVM_NATIVE_MUTEX* (*new_instance)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">);>
30  
31 Creates a new mutex and initialize it, and returns it.
32  
33 =head2 free_instance
34  
35 C<void (*free_instance)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, L<SPVM_NATIVE_MUTEX* mutex|SPVM::Document::NativeAPI::Mutex>);>
36  
37 Destroys the mutex I<mutex> and frees it.
38  
39 =head2 lock
40  
41 C<void (*lock)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, L<SPVM_NATIVE_MUTEX* mutex|SPVM::Document::NativeAPI::Mutex>);>
42  
43 Locks the mutex I<mutex>.
44  
45 Calls the L<pthread_rwlock_wrlock|https://linux.die.net/man/3/pthread_rwlock_wrlock> function in Linux and UNIX.
46  
47 Calls L<AcquireSRWLockExclusive|https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-acquiresrwlockexclusive> function in Windows.
48  
49 =head2 unlock
50  
51 C<void (*unlock)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, L<SPVM_NATIVE_MUTEX* mutex|SPVM::Document::NativeAPI::Mutex>);>
52  
53 Unlocks the mutex I<mutex>.
54  
55 Calls the L<pthread_rwlock_unlock|https://linux.die.net/man/3/pthread_rwlock_unlock> function in Linux and UNIX.
56  
57 Calls L<ReleaseSRWLockExclusive|https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-releasesrwlockexclusive> function in Windows.
58  
59 =head2 reader_lock
60  
61 C<void (*reader_lock)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, L<SPVM_NATIVE_MUTEX* mutex|SPVM::Document::NativeAPI::Mutex>);>
62  
63 Locks the mutex I<mutex> for reading.
64  
65 Calls the L<pthread_rwlock_rdlock|https://linux.die.net/man/3/pthread_rwlock_rdlock> function in Linux and UNIX.
66  
67 Calls L<AcquireSRWLockShared|https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-acquiresrwlockshared> function in Windows.
68  
69 =head2 reader_unlock
70  
71 C<void (*reader_unlock)(L<SPVM_ENV* env|SPVM::Document::NativeClass/"Runtime Environment">, L<SPVM_VALUE* stack|SPVM::Document::NativeClass/"Runtime Stack">, L<SPVM_NATIVE_MUTEX* mutex|SPVM::Document::NativeAPI::Mutex>);>
72  
73 Unlocks the mutex I<mutex> for reading.
74  
75 Calls the L<pthread_rwlock_unlock|https://linux.die.net/man/3/pthread_rwlock_unlock> function in Linux and UNIX.
76  
77 Calls L<ReleaseSRWLockShared|https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-releasesrwlockshared> function in Windows.
78  
79 =head1 Native API IDs
80  
81 0 new_instance
82 1 free_instance
83 2 lock
84 3 unlock
85 4 reader_lock
86 5 reader_unlock
87  
88 =head1 See Also
89  
90 =over 2
91  
92 =item * L<SPVM::Document::NativeAPI>
93  
94 =item * L<SPVM::Document::NativeClass>
95  
96 =item * L<SPVM::Document>
97  
98 =back
99  
100 =head1 Copyright & License
101  
102 Copyright (c) 2023 Yuki Kimoto
103  
104 MIT License