Module: Synctest::Patches::MutexPatch

Defined in:
lib/synctest/patches.rb

Instance Method Summary collapse

Instance Method Details

#initializeObject



212
213
214
215
# File 'lib/synctest/patches.rb', line 212

def initialize(...)
  super
  Synctest.associate(self)
end

#lockObject



217
218
219
220
221
222
# File 'lib/synctest/patches.rb', line 217

def lock
  bubble = Synctest.bubble_for_operation(self)
  return super unless bubble

  bubble.mutex_lock(self)
end

#owned?Boolean

Returns:

  • (Boolean)


238
239
240
241
242
243
# File 'lib/synctest/patches.rb', line 238

def owned?
  bubble = Synctest.bubble_for_operation(self)
  return super unless bubble

  bubble.mutex_owned?(self)
end

#sleep(timeout = nil) ⇒ Object



259
260
261
262
263
264
# File 'lib/synctest/patches.rb', line 259

def sleep(timeout = nil)
  bubble = Synctest.bubble_for_operation(self)
  return super unless bubble

  bubble.mutex_sleep(self, timeout)
end

#synchronizeObject



245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/synctest/patches.rb', line 245

def synchronize
  bubble = Synctest.bubble_for_operation(self)
  return super unless bubble

  locked = false
  begin
    bubble.mutex_lock(self)
    locked = true
    yield
  ensure
    bubble.mutex_unlock(self) if locked
  end
end

#try_lockObject



224
225
226
227
228
229
# File 'lib/synctest/patches.rb', line 224

def try_lock
  bubble = Synctest.bubble_for_operation(self)
  return super unless bubble

  bubble.mutex_try_lock(self)
end

#unlockObject



231
232
233
234
235
236
# File 'lib/synctest/patches.rb', line 231

def unlock
  bubble = Synctest.bubble_for_operation(self)
  return super unless bubble

  bubble.mutex_unlock(self)
end