 
   final override func close()
   {
-    if closed { return }
-
-    OSSpinLockLock(&wlock)
-    closed = true
-    OSSpinLockUnlock(&wlock)
-
-    dispatch_semaphore_signal(filled)
-    dispatch_semaphore_signal(empty)
+    if OSAtomicCompareAndSwapLongBarrier(0, 1, &closed)
+    {
+      dispatch_semaphore_signal(filled)
+      dispatch_semaphore_signal(empty)
+    }
   }
 
   /**

    Determine whether the channel has been closed
  */

  final override var isClosed: Bool { return closed }

  // MARK: ChannelType methods


    }
    else
    {
      assert(closed != 0, __FUNCTION__)
      OSSpinLockUnlock(&rlock)
      dispatch_semaphore_signal(filled)
      return nil
