Change from BoundedSemaphore to Semaphore in Mutex implementation so it will work on Mac OS X (and other platforms with out sem_getvalue().

This commit is contained in:
Patrick Mahoney 2011-12-13 22:03:36 -06:00
parent d102786090
commit 514df0f49f
1 changed files with 10 additions and 10 deletions

View File

@ -1,24 +1,24 @@
require 'process_shared/bounded_semaphore' require 'process_shared/semaphore'
require 'process_shared/with_self' require 'process_shared/with_self'
require 'process_shared/shared_memory' require 'process_shared/shared_memory'
require 'process_shared/process_error' require 'process_shared/process_error'
module ProcessShared module ProcessShared
# This Mutex class is implemented as a BoundedSemaphore with a # This Mutex class is implemented as a Semaphore with a second
# maximum value of 1. Additionally, the locking process is tracked, # internal Semaphore used to track the locking process is tracked.
# and {ProcessError} is raised if either {#unlock} is called by a # {ProcessError} is raised if either {#unlock} is called by a
# process different from the locking process, or if {#lock} is # process different from the locking process, or if {#lock} is
# called while the process already holds the lock (i.e. the mutex is # called while the process already holds the lock (i.e. the mutex is
# not re-entrant). This tracking is not without performance cost, # not re-entrant). This tracking is not without performance cost,
# of course (current implementation uses an additional # of course (current implementation uses the additional {Semaphore}
# {BoundedSemaphore} and {SharedMemory} segment). # and {SharedMemory} segment).
# #
# The API is intended to be identical to the {::Mutex} in the core # The API is intended to be identical to the {::Mutex} in the core
# Ruby library. # Ruby library.
# #
# TODO: the core Ruby api has no #close method, but this Mutex must # TODO: the core Ruby api has no #close method, but this Mutex must
# release its {BoundedSemaphore} and {SharedMemory} resources. For # release its {Semaphore} and {SharedMemory} resources. For now,
# now, rely on the object finalizers of those objects... # rely on the object finalizers of those objects...
class Mutex class Mutex
# include WithSelf # include WithSelf
@ -27,10 +27,10 @@ module ProcessShared
# end # end
def initialize def initialize
@internal_sem = BoundedSemaphore.new(1) @internal_sem = Semaphore.new
@locked_by = SharedMemory.new(:int) @locked_by = SharedMemory.new(:int)
@sem = BoundedSemaphore.new(1) @sem = Semaphore.new
end end
# @return [Mutex] # @return [Mutex]