bsc/vendor/github.com/rjeczalik/notify/watchpoint.go
Péter Szilágyi 289b30715d Godeps, vendor: convert dependency management to trash (#3198)
This commit converts the dependency management from Godeps to the vendor
folder, also switching the tool from godep to trash. Since the upstream tool
lacks a few features proposed via a few PRs, until those PRs are merged in
(if), use github.com/karalabe/trash.

You can update dependencies via trash --update.

All dependencies have been updated to their latest version.

Parts of the build system are reworked to drop old notions of Godeps and
invocation of the go vet command so that it doesn't run against the vendor
folder, as that will just blow up during vetting.

The conversion drops OpenCL (and hence GPU mining support) from ethash and our
codebase. The short reasoning is that there's noone to maintain and having
opencl libs in our deps messes up builds as go install ./... tries to build
them, failing with unsatisfied link errors for the C OpenCL deps.

golang.org/x/net/context is not vendored in. We expect it to be fetched by the
user (i.e. using go get). To keep ci.go builds reproducible the package is
"vendored" in build/_vendor.
2016-10-28 19:05:01 +02:00

104 lines
2.4 KiB
Go

// Copyright (c) 2014-2015 The Notify Authors. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
package notify
// EventDiff describes a change to an event set - EventDiff[0] is an old state,
// while EventDiff[1] is a new state. If event set has not changed (old == new),
// functions typically return the None value.
type eventDiff [2]Event
func (diff eventDiff) Event() Event {
return diff[1] &^ diff[0]
}
// Watchpoint
//
// The nil key holds total event set - logical sum for all registered events.
// It speeds up computing EventDiff for Add method.
//
// The rec key holds an event set for a watchpoints created by RecursiveWatch
// for a Watcher implementation which is not natively recursive.
type watchpoint map[chan<- EventInfo]Event
// None is an empty event diff, think null object.
var none eventDiff
// rec is just a placeholder
var rec = func() (ch chan<- EventInfo) {
ch = make(chan<- EventInfo)
close(ch)
return
}()
func (wp watchpoint) dryAdd(ch chan<- EventInfo, e Event) eventDiff {
if e &^= internal; wp[ch]&e == e {
return none
}
total := wp[ch] &^ internal
return eventDiff{total, total | e}
}
// Add assumes neither c nor e are nil or zero values.
func (wp watchpoint) Add(c chan<- EventInfo, e Event) (diff eventDiff) {
wp[c] |= e
diff[0] = wp[nil]
diff[1] = diff[0] | e
wp[nil] = diff[1] &^ omit
// Strip diff from internal events.
diff[0] &^= internal
diff[1] &^= internal
if diff[0] == diff[1] {
return none
}
return
}
func (wp watchpoint) Del(c chan<- EventInfo, e Event) (diff eventDiff) {
wp[c] &^= e
if wp[c] == 0 {
delete(wp, c)
}
diff[0] = wp[nil]
delete(wp, nil)
if len(wp) != 0 {
// Recalculate total event set.
for _, e := range wp {
diff[1] |= e
}
wp[nil] = diff[1] &^ omit
}
// Strip diff from internal events.
diff[0] &^= internal
diff[1] &^= internal
if diff[0] == diff[1] {
return none
}
return
}
func (wp watchpoint) Dispatch(ei EventInfo, extra Event) {
e := eventmask(ei, extra)
if !matches(wp[nil], e) {
return
}
for ch, eset := range wp {
if ch != nil && matches(eset, e) {
select {
case ch <- ei:
default: // Drop event if receiver is too slow
dbgprintf("dropped %s on %q: receiver too slow", ei.Event(), ei.Path())
}
}
}
}
func (wp watchpoint) Total() Event {
return wp[nil] &^ internal
}
func (wp watchpoint) IsRecursive() bool {
return wp[nil]&recursive != 0
}