// NewSemaphore creates a semaphore that allows up
// to a given limit of simultaneous acquisitions
183083
func NewSemaphore(n int) Semaphore {
	if n == 0 {
		panic("semaphore with limit 0")
	}
	ch := make(chan struct{}, n)
	return Semaphore(ch)
}
1116633
func NewSmaForStream(priceStream gotrade.DOHLCVStreamSubscriber, timePeriod int, selectData gotrade.DOHLCVDataSelectionFunc) (indicator *Sma, err error) {
	ind, err := NewSma(timePeriod, selectData)
	priceStream.AddTickSubscription(ind)
	return ind, err
}
192203
func NewSemVer(s string) (*SemVer, error) {
	nsv, err := semver.NewVersion(s)
	if err != nil {
		return nil, ErrBadSemVer
	}
	v := SemVer(*nsv)
	if v.Empty() {
		return nil, ErrNoZeroSemVer
	}
	return &v, nil
}
35991
func NewSsoRemoveLogoutUrlType(Description string) *SsoRemoveLogoutUrlType {
	s := new(SsoRemoveLogoutUrlType)
	s.Description = Description
	return s
}
829168
func NewSma(timePeriod int, selectData gotrade.DOHLCVDataSelectionFunc) (indicator *Sma, err error) {
	if selectData == nil {
		return nil, ErrDOHLCVDataSelectFuncIsNil
	}

	ind := Sma{
		selectData: selectData,
	}
	ind.SmaWithoutStorage, err = NewSmaWithoutStorage(
		timePeriod,
		func(dataItem float64, streamBarIndex int) {
			ind.Data = append(ind.Data, dataItem)
		})

	return &ind, err
}
118887
func (s *Semaphore) Release() {
	s.rMutex.Lock()
	defer s.rMutex.Unlock()

	s.channel <- struct{}{}

	s.pMutex.Lock()
	s.avail++
	s.pMutex.Unlock()
}
110257
func CreateSemaphore(initialValue uint32) (*Sem, error) {
	sem := C.SDL_CreateSemaphore(C.Uint32(initialValue))
	if sem == nil {
		return nil, GetError()
	}
	return (*Sem)(unsafe.Pointer(sem)), nil
}
192126
func (conn *ProtoConnection) NewSyncPublisher(topic string) (messaging.ProtoPublisher, error) {
	return &protoSyncPublisherKafka{conn, topic}, nil
}
271348
func NewSelector(client RESTClient, mapping *meta.RESTMapping, namespace string, selector labels.Selector, export bool) *Selector {
	return &Selector{
		Client:    client,
		Mapping:   mapping,
		Namespace: namespace,
		Selector:  selector,
		Export:    export,
	}
}
42773
func NewSpritesheetFromTexture(tr *TextureResource, cellWidth, cellHeight int) *Spritesheet {
	spriteRegions := generateSymmetricSpriteRegions(tr.Width, tr.Height, cellWidth, cellHeight, 0, 0)
	return NewAsymmetricSpritesheetFromTexture(tr, spriteRegions)
}
179484
func NewSetCustomObjectFormatterEnabledArgs(enabled bool) *SetCustomObjectFormatterEnabledArgs {
	args := new(SetCustomObjectFormatterEnabledArgs)
	args.Enabled = enabled
	return args
}
1240100
func (p *Plugin) NewSyncPublisher(connectionName string, topic string) (messaging.ProtoPublisher, error) {
	return p.NewProtoConnection(connectionName).NewSyncPublisher(topic)
}
646387
func NewSupervisor(store *store.MemoryStore, restartSupervisor *restart.Supervisor) *Supervisor {
	return &Supervisor{
		store:    store,
		updates:  make(map[string]*Updater),
		restarts: restartSupervisor,
	}
}
239081
func NewSubnet(a Address, m AddressMask) (Subnet, error) {
	if len(a) != len(m) {
		return Subnet{}, errSubnetLengthMismatch
	}
	for i := 0; i < len(a); i++ {
		if a[i]&^m[i] != 0 {
			return Subnet{}, errSubnetAddressMasked
		}
	}
	return Subnet{a, m}, nil
}
1293589
func (s *Semaphore) addHolder(h string) error {
	loc := sort.SearchStrings(s.Holders, h)
	switch {
	case loc == len(s.Holders):
		s.Holders = append(s.Holders, h)
	case s.Holders[loc] == h:
		return ErrExist
	default:
		s.Holders = append(s.Holders[:loc], append([]string{h}, s.Holders[loc:]...)...)
	}

	return nil
}
1215688
func NewScanPolicy() *ScanPolicy {
	mp := *NewMultiPolicy()
	mp.TotalTimeout = 0

	return &ScanPolicy{
		MultiPolicy:     mp,
		ScanPercent:     100,
		ConcurrentNodes: true,
	}
}
1083794
func (bt *backpressureTracker) updateSemaphoreMax() {
	newMax := int64(bt.currLimit())
	delta := newMax - bt.semaphoreMax
	// These operations are adjusting the *maximum* value of
	// bt.semaphore.
	if delta > 0 {
		bt.semaphore.Release(delta)
	} else if delta < 0 {
		bt.semaphore.ForceAcquire(-delta)
	}
	bt.semaphoreMax = newMax
}