           OSSpinLockUnlock(&lock)
           s.svalue = 0
           s.iptr = nil
-          s.currentState = ChannelSemaphoreState.Ready.rawValue
+          s.currentState = ChannelSemaphore.State.Ready.rawValue
           return s
         }
       }

  }
}

// MARK: ChannelSemaphoreState

enum ChannelSemaphoreState: Int32
{
case Ready

// Unbuffered channel data
case Pointer

// Select() case
case WaitSelect
case Select
case DoubleSelect
case Invalidated

// End state
case Done
}

// MARK: ChannelSemaphore

/**
  A benaphore: http://www.haiku-os.org/legacy-docs/benewsletter/Issue1-26.html
  Also: http://preshing.com/20120226/roll-your-own-lightweight-mutex/

  Much like dispatch_semaphore_t, with native Swift typing. (And state information.)
  Versions of libdispatch are at: http://www.opensource.apple.com/source/libdispatch/
*/

final public class ChannelSemaphore
{
  private var svalue: Int32
  private var semp = semaphore_t()

  private var currentState = ChannelSemaphoreState.Ready.rawValue
  private var iptr: UnsafeMutablePointer<Void> = nil
  private var seln: Selection? = nil

  // MARK: init/deinit

  init(value: Int)

        OSSpinLockUnlock(&lock)
        s.svalue = 0
        s.iptr = nil
        s.currentState = ChannelSemaphore.State.Ready.rawValue
        return s
      }

