util.go 639 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
package dht

import (
	"sync"
)

// Pool size is the number of nodes used for group find/set RPC calls
var PoolSize = 6

Jeromy's avatar
Jeromy committed
10
// K is the maximum number of requests to perform before returning failure.
11 12
var KValue = 10

Jeromy's avatar
Jeromy committed
13
// Alpha is the concurrency factor for asynchronous requests.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
var AlphaValue = 3

// A counter for incrementing a variable across multiple threads
type counter struct {
	n   int
	mut sync.Mutex
}

func (c *counter) Increment() {
	c.mut.Lock()
	c.n++
	c.mut.Unlock()
}

func (c *counter) Decrement() {
	c.mut.Lock()
	c.n--
	c.mut.Unlock()
}

func (c *counter) Size() (s int) {
	c.mut.Lock()
	s = c.n
	c.mut.Unlock()
	return
}