func (v *Valve) SetCap(n int) error {
	// Lock the send system
	su := v.send.TryLock()
	if su == nil {
		v.ErrorFile.Set("concurring send attempt")
		return rh.ErrPerm
	}
	defer su.Unlock()

	// Lock the receive system
	ru := v.recv.TryLock()
	if ru == nil {
		v.ErrorFile.Set("concurring receive attempt")
		return rh.ErrPerm
	}
	defer ru.Unlock()

	// Lock the control system
	v.ctrl.Lock()
	defer v.ctrl.Unlock()

	// Validate argument and check we are not opening twice
	if v.ctrl.stat.Opened {
		v.ErrorFile.Set("capacity already set")
		return rh.ErrClash
	}
	if n < 0 {
		v.ErrorFile.Set("negative capacity")
		return rh.ErrPerm
	}

	// Initialize valve
	tun, abr := make(chan chan interruptible.Reader, n), make(chan struct{})
	v.send.tun, v.recv.tun = tun, tun                  // setup main channel
	v.ctrl.abr, v.send.abr, v.recv.abr = abr, abr, abr // setup abort channel
	v.ctrl.stat.Opened, v.ctrl.stat.Cap = true, n                // update state

	return nil
}
// SetCap initializes the valve and sets its buffer capacity to n.
SetCap initializes the valve and sets its buffer capacity to n.
// SetCap initializes the valve and sets its buffer capacity to n .
func (v *Valve) SetCap(n int) error {
	su := v.send.TryLock()
	if su == nil {
		v.ErrorFile.Set("concurring send attempt")
		return rh.ErrPerm
	}
	defer su.Unlock()
	ru := v.recv.TryLock()
	if ru == nil {
		v.ErrorFile.Set("concurring receive attempt")
		return rh.ErrPerm
	}
	defer ru.Unlock()
	v.ctrl.Lock()
	defer v.ctrl.Unlock()
	if v.ctrl.stat.Opened {
		v.ErrorFile.Set("capacity already set")
		return rh.ErrClash
	}
	if n < 0 {
		v.ErrorFile.Set("negative capacity")
		return rh.ErrPerm
	}
	tun, abr := make(chan chan interruptible.Reader, n), make(chan struct{})
	v.send.tun, v.recv.tun = tun, tun                  
	v.ctrl.abr, v.send.abr, v.recv.abr = abr, abr, abr 
	v.ctrl.stat.Opened, v.ctrl.stat.Cap = true, n                
	return nil
}
func ( v * Valve ) SetCap ( n int ) error { su := v . send . TryLock ( ) if su == nil { v . ErrorFile . Set ( " " ) return rh . ErrPerm } defer su . Unlock ( ) ru := v . recv . TryLock ( ) if ru == nil { v . ErrorFile . Set ( " " ) return rh . ErrPerm } defer ru . Unlock ( ) v . ctrl . Lock ( ) defer v . ctrl . Unlock ( ) if v . ctrl . stat . Opened { v . ErrorFile . Set ( " " ) return rh . ErrClash } if n < 0 { v . ErrorFile . Set ( " " ) return rh . ErrPerm } tun , abr := make ( chan chan interruptible . Reader , n ) , make ( chan struct { } ) v . send . tun , v . recv . tun = tun , tun v . ctrl . abr , v . send . abr , v . recv . abr = abr , abr , abr v . ctrl . stat . Opened , v . ctrl . stat . Cap = true , n return nil }
SetCap initializes the valve and sets its buffer capacity to n.
SetCap initializes the valve and sets its buffer capacity to n .
// Lock the send system // Lock the receive system // Lock the control system // Validate argument and check we are not opening twice // Initialize valve // setup main channel // setup abort channel // update state