Class: Baykit::BayServer::Util::Counter
- Inherits:
-
Object
- Object
- Baykit::BayServer::Util::Counter
- Defined in:
- lib/baykit/bayserver/util/counter.rb
Instance Attribute Summary collapse
-
#counter ⇒ Object
readonly
Returns the value of attribute counter.
-
#mutex ⇒ Object
readonly
Returns the value of attribute mutex.
Instance Method Summary collapse
-
#initialize(init = 1) ⇒ Counter
constructor
A new instance of Counter.
- #next ⇒ Object
Constructor Details
#initialize(init = 1) ⇒ Counter
Returns a new instance of Counter.
8 9 10 11 |
# File 'lib/baykit/bayserver/util/counter.rb', line 8 def initialize(init=1) @counter = init @mutex = Mutex.new end |
Instance Attribute Details
#counter ⇒ Object (readonly)
Returns the value of attribute counter.
5 6 7 |
# File 'lib/baykit/bayserver/util/counter.rb', line 5 def counter @counter end |
#mutex ⇒ Object (readonly)
Returns the value of attribute mutex.
6 7 8 |
# File 'lib/baykit/bayserver/util/counter.rb', line 6 def mutex @mutex end |
Instance Method Details
#next ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/baykit/bayserver/util/counter.rb', line 13 def next @mutex.synchronize do c = @counter @counter += 1 c end end |