/*
Capacity returns the current capacity of the ring buffer.
*/
17522
func (r *Ring) Capacity() int {
	r.Lock()
	defer r.Unlock()

	return r.capacity()
}
550700
func (c C) Ring1(val Input) Input {
	if v, ok := val.(C); ok {
		return C((c * v) + c)
	}
	return val.Ring1(c)
}
16368
func (q *InMemoryQueueStorage) QueueSize() (int, error) {
	q.lock.Lock()
	defer q.lock.Unlock()
	return q.size, nil
}
125051
func (m *pool) Capacity() int {
	masked, total := m.dynamicRange.Mask.Size()
	return int(math.Pow(2, float64(total-masked)) / 4)
}
249819
func (rb *ringBuffer) String() string {
	vs := []string{}
	current := rb.start
	for current.used {
		vs = append(vs, fmt.Sprintf("[%v]", current.value))
		current = current.next
		if current == rb.start {
			break
		}
	}
	return strings.Join(vs, "->")
}
833203
func (as ArraySpec) Ring1(val Input) Input {
	return as.proc(func(i Input) Input {
		return i.Ring1(val)
	})
}
1247571
func SetHistoryCapacity(capacity int) error { // int linenoiseHistorySetMaxLen(int len);
	res := C.linenoiseHistorySetMaxLen(C.int(capacity))
	if res != 1 {
		return errors.New("Could not set history max len.")
	}
	return nil
}
1084406
func (b *PayloadsBufferImpl) Size() int {
	b.mutex.RLock()
	defer b.mutex.RUnlock()
	return len(b.buf)
}
1225811
func (a *adapter) Write(app string, message string) error {
	// Check first if we might actually have to add to the map of ringBuffer pointers so we can avoid
	// waiting for / obtaining a lock unnecessarily
	rb, ok := a.ringBuffers[app]
	if !ok {
		// Ensure only one goroutine at a time can be adding a ringBuffer to the map of ringBuffers
		// pointers
		a.mutex.Lock()
		defer a.mutex.Unlock()
		rb, ok = a.ringBuffers[app]
		if !ok {
			rb = newRingBuffer(a.bufferSize)
			a.ringBuffers[app] = rb
		}
	}
	rb.write(message)
	return nil
}
1246906
func (as ArraySpec) Ring3(val Input) Input {
	return as.proc(func(i Input) Input {
		return i.Ring3(val)
	})
}
314650
func (b *CircularBuffer) Get() interface{} {
	_ = <-b.avail

	b.lock.Lock()
	defer b.lock.Unlock()

	if b.start == b.pos {
		panic("Trying to get from empty buffer")
	}

	v := b.buffer[b.start]
	b.buffer[b.start] = nil
	b.start = (b.start + 1) % b.size

	return v
}
320412
func (d *Context) GetBuffer(index int) (rawPtr unsafe.Pointer, outSize uint) {
	rawPtr = C.duk_get_buffer(d.duk_context, C.duk_idx_t(index), (*C.duk_size_t)(unsafe.Pointer(&outSize)))
	return rawPtr, outSize
}
883548
func (c C) Ring3(val Input) Input {
	if v, ok := val.(C); ok {
		return C((c * v) * v)
	}
	return val.Ring3(c)
}
812528
func (b *Buffer) Size() int {
	size := len(b.Buf)
	for _, buf := range b.bufs {
		size += len(buf)
	}
	return size
}
1337341
func (_class NetworkSriovClass) GetRemainingCapacity(sessionID SessionRef, self NetworkSriovRef) (_retval int, _err error) {
	_method := "network_sriov.get_remaining_capacity"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_selfArg, _err := convertNetworkSriovRefToXen(fmt.Sprintf("%s(%s)", _method, "self"), self)
	if _err != nil {
		return
	}
	_result, _err := _class.client.APICall(_method, _sessionIDArg, _selfArg)
	if _err != nil {
		return
	}
	_retval, _err = convertIntToGo(_method + " -> ", _result.Value)
	return
}
967853
func (r *Cache) SetCapacity(capacity int) {
	if r.cacher != nil {
		r.cacher.SetCapacity(capacity)
	}
}
649178
func reserveBuffer(buf []byte, appendSize int) []byte {
	newSize := len(buf) + appendSize
	if cap(buf) < newSize {
		// Grow buffer exponentially
		newBuf := make([]byte, len(buf)*2+appendSize)
		copy(newBuf, buf)
		buf = newBuf
	}
	return buf[:newSize]
}