summaryrefslogtreecommitdiff
path: root/src/atomicbool.go
blob: f2f4894fdc275648d6bd0e6456021883158a95ff (plain)
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
package fzf

import "sync"

type AtomicBool struct {
	mutex sync.Mutex
	state bool
}

func NewAtomicBool(initialState bool) *AtomicBool {
	return &AtomicBool{
		mutex: sync.Mutex{},
		state: initialState}
}

func (a *AtomicBool) Get() bool {
	a.mutex.Lock()
	defer a.mutex.Unlock()
	return a.state
}

func (a *AtomicBool) Set(newState bool) bool {
	a.mutex.Lock()
	defer a.mutex.Unlock()
	a.state = newState
	return a.state
}