Class: PThread::Mutex
Constant Summary
Constants included
from Helper
Helper::MAP_FAILED, Helper::MAP_PRIVATE, Helper::MAP_SHARED, Helper::O_CREAT, Helper::O_RDWR, Helper::PROT_EXEC, Helper::PROT_NONE, Helper::PROT_READ, Helper::PROT_WRITE, Helper::PTHREAD_PROCESS_SHARED
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from PThread
call, test
Constructor Details
#initialize(mutex = Mutex.alloc, attr = nil) ⇒ Mutex
Returns a new instance of Mutex.
183
184
185
186
|
# File 'lib/scratch.rb', line 183
def initialize(mutex = Mutex.alloc, attr = nil)
@mutex = mutex
PThread.call { pthread_mutex_init(@mutex, attr) }
end
|
Class Method Details
.alloc ⇒ Object
178
179
180
|
# File 'lib/scratch.rb', line 178
def alloc
FFI::MemoryPointer.new(Helper.sizeof_pthread_mutex_t)
end
|
Instance Method Details
#destroy ⇒ Object
188
189
190
|
# File 'lib/scratch.rb', line 188
def destroy
PThread.call { pthread_mutex_destroy(@mutex) }
end
|
#lock ⇒ Object
192
193
194
|
# File 'lib/scratch.rb', line 192
def lock
PThread.call { pthread_mutex_lock(@mutex) }
end
|
#try_lock ⇒ Object
196
197
198
|
# File 'lib/scratch.rb', line 196
def try_lock
PThread.call { pthread_mutex_trylock(@mutex) }
end
|
#unlock ⇒ Object
200
201
202
|
# File 'lib/scratch.rb', line 200
def unlock
PThread.call { pthread_mutex_unlock(@mutex) }
end
|