| // Copyright 2015 The Vanadium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| // watchers provides syncronization and notifications for a shared resource. |
| clients map[int][]chan struct{} |
| func (p *watchers) lock() { |
| func (p *watchers) unlock(id int) { |
| for i, c := range p.clients { |
| // Non-blocking send. If the channel is full we don't need |
| // to send a duplicate flush. |
| func (p *watchers) rlock() { |
| func (p *watchers) runlock() { |
| func (p *watchers) newID() int { |
| func (p *watchers) register(id int) chan struct{} { |
| ch := make(chan struct{}, 1) |
| p.clients[id] = append(p.clients[id], ch) |
| func (p *watchers) unregister(id int, ch chan struct{}) { |
| for i, v := range clients { |
| clients[i], clients[max], p.clients[id] = clients[max], nil, clients[:max] |
| func newWatchers() *watchers { |
| return &watchers{clients: make(map[int][]chan struct{})} |