# Path: rx/concurrency.py
# class Atomic:
#   def __init__(self, value=None, lock=RLock()):
#     self.lock = lock
#     self._value = value
# 
#   def value():
#       doc = "The value property."
#       def fget(self):
#           return self._value
#       def fset(self, value):
#           self.exchange(value)
#       return locals()
#   value = property(**value())
# 
#   def exchange(self, value):
#     with self.lock:
#       old = self._value
#       self._value = value
#       return old
# 
#   def compareExchange(self, value, expected):
#     with self.lock:
#       old = self._value
# 
#       if old == expected:
#         self._value = value
# 
#       return old
# 
#   def inc(self, by=1):
#     with self.lock:
#       self._value += by
#       return self.value
# 
#   def dec(self, by=1):
#     with self.lock:
#       self._value -= by
#       return self.value


from rx.concurrency import Atomic
from collections import deque
      self.length -= 1

    if shouldDispose:
      disposable.dispose()

    return shouldDispose

  def clear(self):
    disposables = []

    with self.lock:
      disposables = self.disposables
      self.disposables = []
      self.length = 0

    for disposable in disposables:
      disposable.dispose()

  def dispose(self):
    if not self._isDisposed.exchange(True):
      self.clear()


class RefCountDisposable(Cancelable):
  """Represents a disposable resource that only disposes
  its underlying disposable resource when all
  dependent disposable objects have been disposed."""

  class InnerDisposable(Disposable):
    def __init__(self, parent):

# Path: rx/concurrency.py
# class Atomic:
#   def __init__(self, value=None, lock=RLock()):
#     self.lock = lock
#     self._value = value
# 
#   def value():
#       doc = "The value property."
#       def fget(self):
#           return self._value
#       def fset(self, value):
#           self.exchange(value)
#       return locals()
#   value = property(**value())
# 
#   def exchange(self, value):
#     with self.lock:
#       old = self._value
#       self._value = value
#       return old
# 
#   def compareExchange(self, value, expected):
#     with self.lock:
#       old = self._value
# 
#       if old == expected:
#         self._value = value
# 
#       return old
# 
#   def inc(self, by=1):
#     with self.lock:
#       self._value += by
#       return self.value
# 
#   def dec(self, by=1):
#     with self.lock:
#       self._value -= by
#       return self.value


# Path: rx/disposable.py
from rx.concurrency import Atomic
from collections import deque

      self.length -= 1

    if shouldDispose:
      disposable.dispose()

    return shouldDispose

  def clear(self):
    disposables = []

    with self.lock:
      disposables = self.disposables
      self.disposables = []
      self.length = 0

    for disposable in disposables:
      disposable.dispose()

  def dispose(self):
    if not self._isDisposed.exchange(True):
      self.clear()


class RefCountDisposable(Cancelable):
  """Represents a disposable resource that only disposes
  its underlying disposable resource when all
  dependent disposable objects have been disposed."""

  class InnerDisposable(Disposable):
    def __init__(self, parent):

      self.parent = Atomic(parent)