Esempio n. 1
0
package profile

import (
	"github.com/idealeak/goserver/core/container/recycler"
)

const (
	WatcherRecyclerBacklog int = 128
)

var WatcherRecycler = recycler.NewRecycler(
	WatcherRecyclerBacklog,
	func() interface{} {
		return &TimeWatcher{}
	},
	"watcher_recycler",
)

func AllocWatcher() *TimeWatcher {
	t := WatcherRecycler.Get()
	return t.(*TimeWatcher)
}

func FreeWatcher(t *TimeWatcher) {
	WatcherRecycler.Give(t)
}
Esempio n. 2
0
package netlib

import (
	"github.com/idealeak/goserver/core/container/recycler"
)

const (
	RWBufRecyclerBacklog int = 128
)

var RWRecycler = recycler.NewRecycler(
	RWBufRecyclerBacklog,
	func() interface{} {
		rb := &RWBuffer{
			buf: make([]byte, 0, MaxPacketSize),
		}

		return rb
	},
	"rwbuf_recycler",
)

func AllocRWBuf() *RWBuffer {
	b := RWRecycler.Get()
	rb := b.(*RWBuffer)
	rb.Init()
	return rb
}

func FreeRWBuf(buf *RWBuffer) {
	RWRecycler.Give(buf)
Esempio n. 3
0
package netlib

import (
	"github.com/idealeak/goserver/core/container/recycler"
)

const (
	ActionRecyclerBacklog int = 128
)

var ActionRecycler = recycler.NewRecycler(
	ActionRecyclerBacklog,
	func() interface{} {
		return &action{}
	},
	"action_recycler",
)

func AllocAction() *action {
	a := ActionRecycler.Get()
	return a.(*action)
}

func FreeAction(a *action) {
	ActionRecycler.Give(a)
}