File: chanpool.go

package info (click to toggle)
golang-github-zenazn-goji 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: makefile: 3
file content (31 lines) | stat: -rw-r--r-- 443 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// +build !go1.3

package web

// This is an alternate implementation of Go 1.3's sync.Pool.

// Maximum size of the pool of spare middleware stacks
const cPoolSize = 32

type cPool chan *cStack

func makeCPool() *cPool {
	p := make(cPool, cPoolSize)
	return &p
}

func (c cPool) alloc() *cStack {
	select {
	case cs := <-c:
		return cs
	default:
		return nil
	}
}

func (c cPool) release(cs *cStack) {
	select {
	case c <- cs:
	default:
	}
}