aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/rjeczalik/notify/watchpoint.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/rjeczalik/notify/watchpoint.go')
-rw-r--r--vendor/github.com/rjeczalik/notify/watchpoint.go103
1 files changed, 103 insertions, 0 deletions
diff --git a/vendor/github.com/rjeczalik/notify/watchpoint.go b/vendor/github.com/rjeczalik/notify/watchpoint.go
new file mode 100644
index 000000000..5afc914f4
--- /dev/null
+++ b/vendor/github.com/rjeczalik/notify/watchpoint.go
@@ -0,0 +1,103 @@
+// 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
+}
class='insertions'>+1 * BROKEN: Leaves behind config file on deinstallkris2007-01-111-0/+2 * Update to KDE 3.5.5 / KOffice 1.6.1lofi2006-12-2011-18/+21 * KDE 3.5.4 / KOffice 1.5.2lofi2006-09-1310-30/+24 * All dictionaries can be installed separately:thierry2006-07-154-7/+18 * Update to KDE 3.5.3lofi2006-06-064-16/+16 * Update to KOffice 1.5.1lofi2006-05-276-12/+12 * Update to KOffice 1.5.0lofi2006-04-299-78/+51 * Update to KDE 3.5.2lofi2006-03-314-122/+16 * Update to KDE 3.5.1.lofi2006-02-014-6/+14 * SHA256ifyedwin2006-01-245-0/+5 * Removed not needed distinfo and add empty MASTERSITES and DISTFILES for fix p...anray2006-01-172-3/+2 * Distfile moved to FILESDIR.anray2006-01-172-5/+108 * Update to KDE 3.5.0lofi2006-01-094-110/+68 * KOI8-U coding system for all emacsen.anray2005-12-165-0/+46 * Update to KDE 3.4.3 / KOffice 1.4.2lofi2005-11-052-4/+4 * Remove expired portskris2005-11-0519-3074/+0 * Do the same trick with uk-pine.language as done with ru-pine.languageedwin2005-11-043-8/+41 * Remove all the secondary port of editors/ooodict-allmaho2005-11-012-21/+0 * Fix index build by moving openoffice.org-1.1 ports.maho2005-08-291-1/+1 * Update to KDE 3.4.2 / KOffice 1.4.1lofi2005-08-0110-115/+37 * This port is scheduled for deletion on 2005-09-22 if it is still brokenkris2005-07-232-0/+4 * Update to KDE 3.4.1lofi2005-06-267-17/+6 * - Unbreak and general updatepav2005-06-061-1/+2 * Update to KDE 3.4lofi2005-03-217-66/+233 * BROKEN: Removes config file at deinstall-timekris2005-02-281-0/+2 * BROKEN: Incomplete pkg-plistkris2005-02-191-0/+2 * Add i18nized doc subdirs to kdehier and adjust i18n port plists accordingly.lofi2004-12-235-5/+3 * Tweak IGNORE string to give a better-worded error message.kris2004-12-193-3/+3 * Fix kde3-i18n ports.lofi2004-12-162-4/+4 * Update to KDE 3.3.2lofi2004-12-149-17/+119 * BROKEN on 5.x: Does not compilekris2004-11-191-0/+4 * Update to KDE 3.3.1lofi2004-11-087-12/+32 * Update to KDE 3.3lofi2004-08-3112-15/+17 * Reset maintainer:kris2004-08-161-1/+1 * Pet portlint.lofi2004-07-116-3/+9 * Update to version 3.2.3lofi2004-06-107-16/+27 * Oops. Forgot the language categories.lofi2004-05-076-3/+3 * Update to KDE 3.2.2lofi2004-04-204-32/+22 * Remove category pkg/COMMENT files in favour of a COMMENT variable in thekris2004-04-022-1/+2 * SIZEify (maintainer timeout)trevor2004-03-313-0/+3 * Add ispellkris2004-03-171-0/+1 * Whoa there, boy, that's a mighty big commit y'all have there...ade2004-03-141-3/+3 * Update to KDE 3.2.1 / QT 3.3.1lofi2004-03-109-4/+27 * Use PLIST_FILES (bento-tested, marcus-reviewed).trevor2004-02-062-1/+1 * Update to KDE 3.2.0lofi2004-02-059-54/+136 * Bump PORTREVISION on all ports that depend on gettext to aid with upgrading.marcus2004-02-041-0/+1 * Add USE_GETTEXT and bump PORTREVISION.marcus2004-02-045-10/+10 * - Fix build on 4.xpav2004-01-263-1/+14 * Now gettext 0.12.1 is gettext-old.trevor2004-01-245-5/+5 * - fix PKGORIGINeik2004-01-231-1/+1 * - Update to 5.60pav2004-01-11171-2801/+2714 * Upgrade from 0.5 to 0.7.mi2003-12-102-2/+2 * OpenOffice -> OpenOffice.orgmaho2003-11-091-1/+1 * rename openoffice* to openoffice-1.0* accodingly (repo copy).maho2003-11-081-1/+1 * Mark BROKEN (see bento logs). These ports are scheduled for removalkris2003-11-031-0/+2 * Unbreak BROKEN messageedwin2003-10-131-1/+1 * New port: Ukrainian accounting system. New port of Ukrainian accounting syste...edwin2003-10-10176-0/+3136 * Translation update: fix checksum.will2003-09-222-2/+2 * Upgrade to Qt 3.2.1 / KDE 3.1.4. See x11/kde3/Makefile rev 1.64 for details.will2003-09-182-4/+2 * o Main modificationnork2003-08-191-1/+1 * Update KDE to the latest official release, KDE 3.1.3lofi2003-07-294-6/+16 * Update to KDE 3.1.2lioux2003-05-204-10/+8 * New port: localized messages and documentation for kofficelioux2003-05-2013-0/+208