Class: Thread::Task::Counter

Inherits:
Object
  • Object
show all
Defined in:
lib/thread/task/base.rb

Instance Method Summary collapse

Constructor Details

#initializeCounter

Returns a new instance of Counter.



89
90
91
92
# File 'lib/thread/task/base.rb', line 89

def initialize
  @count  =  0
  @mutex  =  Mutex.new
end

Instance Method Details

#decrObject



100
101
102
103
104
105
# File 'lib/thread/task/base.rb', line 100

def decr
  @mutex.synchronize do
    @count  -=  1    if  @count > 0
    @count
  end
end

#incrObject



94
95
96
97
98
# File 'lib/thread/task/base.rb', line 94

def incr
  @mutex.synchronize do
    @count  +=  1
  end
end

#resetObject



107
108
109
110
111
# File 'lib/thread/task/base.rb', line 107

def reset
  @mutex.synchronize do
    @count  =  0
  end
end