aboutsummaryrefslogtreecommitdiffstats
path: root/event
diff options
context:
space:
mode:
Diffstat (limited to 'event')
-rw-r--r--event/feed.go16
1 files changed, 5 insertions, 11 deletions
diff --git a/event/feed.go b/event/feed.go
index 4568304df..b1b597f17 100644
--- a/event/feed.go
+++ b/event/feed.go
@@ -33,9 +33,8 @@ var errBadChannel = errors.New("event: Subscribe argument does not have sendable
//
// The zero value is ready to use.
type Feed struct {
- // sendLock has a one-element buffer and is empty when held.
- // It protects sendCases.
- sendLock chan struct{}
+ once sync.Once // ensures that init only runs once
+ sendLock chan struct{} // sendLock has a one-element buffer and is empty when held.It protects sendCases.
removeSub chan interface{} // interrupts Send
sendCases caseList // the active set of select cases used by Send
@@ -60,9 +59,6 @@ func (e feedTypeError) Error() string {
}
func (f *Feed) init() {
- if f.sendLock != nil {
- return
- }
f.removeSub = make(chan interface{})
f.sendLock = make(chan struct{}, 1)
f.sendLock <- struct{}{}
@@ -75,6 +71,8 @@ func (f *Feed) init() {
// The channel should have ample buffer space to avoid blocking other subscribers.
// Slow subscribers are not dropped.
func (f *Feed) Subscribe(channel interface{}) Subscription {
+ f.once.Do(f.init)
+
chanval := reflect.ValueOf(channel)
chantyp := chanval.Type()
if chantyp.Kind() != reflect.Chan || chantyp.ChanDir()&reflect.SendDir == 0 {
@@ -84,7 +82,6 @@ func (f *Feed) Subscribe(channel interface{}) Subscription {
f.mu.Lock()
defer f.mu.Unlock()
- f.init()
if !f.typecheck(chantyp.Elem()) {
panic(feedTypeError{op: "Subscribe", got: chantyp, want: reflect.ChanOf(reflect.SendDir, f.etype)})
}
@@ -130,10 +127,7 @@ func (f *Feed) remove(sub *feedSub) {
// Send delivers to all subscribed channels simultaneously.
// It returns the number of subscribers that the value was sent to.
func (f *Feed) Send(value interface{}) (nsent int) {
- f.mu.Lock()
- f.init()
- f.mu.Unlock()
-
+ f.once.Do(f.init)
<-f.sendLock
// Add new cases from the inbox after taking the send lock.
2003-10-201-1/+7 * Update port:erwin2003-10-203-2/+3 * Define __STRICT_ANSI__ when compiling glimpse so it will use <stdarg.h>des2003-10-201-8/+2 * Needs 5.6.1mat2003-10-201-1/+7 * - Layout for GnuSTEP 1.8.0dinoex2003-10-191-5/+1 * Utilize PYTHON_SITE_SUBDIR and USE_PYTHON.perky2003-10-191-1/+1 * Unbreak by depending on glib 2.0 instead of 1.2.knu2003-10-181-3/+4 * Update to 0.05mat2003-10-182-2/+2 * Update to 0.50.4.1. From the official announcement:naddy2003-10-182-5/+6 * asmodai is no longer a committer.kris2003-10-181-1/+1 * Avoid building lstat.o since we have lstat in libc.dd2003-10-181-0/+11 * Correct a typo in an informational message. No functional change.ceri2003-10-183-3/+3 * Update to version 1.65.gerald2003-10-172-2/+2 * Put C*FLAGS into CONFIGURE_ENV instead of assigning it directly. Thisdd2003-10-171-1/+2 * Add p5-RTF-Parser 1.07, perl module for parsing RTF files.vanilla2003-10-175-0/+51 * Add p5-RTF-Tokenizer 1.04, perl module for reading RTF files.vanilla2003-10-175-0/+44 * Add p5-RTF-Writer 1.09,vanilla2003-10-175-0/+54 * Add p5-UML-Sequence 0.05,vanilla2003-10-175-0/+82 * Add p5-UML-State 0.02,vanilla2003-10-175-0/+45 * Add p5-Text-Netstring 0.04,vanilla2003-10-175-0/+37 * Correct pkg-plist.nobutaka2003-10-162-1/+2 * Updated to 0.06skv2003-10-162-2/+2 * Removed empty file.dd2003-10-161-0/+0 * Upgrade to 1.9.7.dd2003-10-164-33/+10 * Before committing the previous BROKEN changes I carefully checked the statuskris2003-10-161-7/+1 * BROKEN on 5.x: does not compilekris2003-10-161-1/+7 * BROKEN on 5.x: does not compilekris2003-10-162-2/+14 * Use ${REINPLACE_CMD} instead of ${PERL}.obrien2003-10-161-3/+4 * Update to 0.1.2.nobutaka2003-10-153-3/+4 * Change the usage of xhtml.soc file.kuriyama2003-10-153-12/+6 * Add p5-XML-STX 0.42, a pure Perl STX processor.skv2003-10-155-0/+85 * Add p5-XML-Validator-Schema 1.04,mat2003-10-145-0/+76 * Update port: textproc/p5-WordNet-QueryData from 1.28 to 1.31vanilla2003-10-142-5/+4 * Add p5-XML-Hadler-HTMLWriter 2.01,mat2003-10-145-0/+42 * Add p5-XML-DTDParser 1.7, perl module for parsing XML DTD strings.mat2003-10-145-0/+50 * Update to 1.3erwin2003-10-142-2/+2 * Update to 2.04mat2003-10-142-3/+3 * Update to 1.12mat2003-10-144-10/+11 * Update port: textproc/xmlcatmgr 1.1edwin2003-10-143-3/+8 * Update to 0.1.1.nobutaka2003-10-138-81/+32 * Add p5-Regex-PreSuf 1.15mat2003-10-135-0/+36 * Updated to 1.00skv2003-10-134-20/+12 * Forgot 5.6.x requirementmat2003-10-131-1/+7 * Add p5-XML-Smartmat2003-10-135-0/+58 * BROKEN: Does not configure (different errors on 4.x and 5.x)kris2003-10-131-0/+2 * BROKEN: Broken pkg-plistkris2003-10-131-0/+2 * intltool and xml-i18n-tools conflict with each other.marcus2003-10-112-0/+4 * Maintainer update: textproc/dico (1.1)edwin2003-10-103-38/+37 * Update to 0.3r77erwin2003-10-104-4/+4 * [new port] textproc/sagasuedwin2003-10-106-0/+75 * Grab maintainershipmat2003-10-101-1/+1 * Update to latest verion 1.8.2lev2003-10-094-25/+46 * Update to 1.66.roam2003-10-095-19/+21 * Update textproc/diffutilsedwin2003-10-094-43/+21 * Add makefaq 2.4, makefaq is a Python program that creates akrion2003-10-085-0/+48 * add missing / (slip of the fingers)edwin2003-10-081-1/+1 * add mirror of the asm2html package.edwin2003-10-081-1/+2 * New port: www/webcpp (converts code to highlighted HTML)edwin2003-10-084-0/+139 * Fix MASTER_SITESerwin2003-10-081-1/+1 * - Fix MASTER_SITESkrion2003-10-071-1/+1 * . Update to 3.2. This is slightly nastier than it should be as fetch(1)glewis2003-10-073-239/+184 * add WWWijliao2003-10-061-0/+2 * Correct some obsolete MASTER_SITESmarcus2003-10-061-1/+1 * Fix paths to consider site specific prefixes.se2003-10-051-31/+32 * Update to 0.9.70arved2003-10-055-33/+36 * update to antiword-0.34leeym2003-10-053-43/+48 * - Update to version 0.50.4krion2003-10-052-7/+5 * Chase lib version change of graphics/ImageMagick.nork2003-10-051-1/+2 * Add cl-ppcre-clisp 0.5.4foxfair2003-10-034-0/+56 * Add cl-meta-clisp 20011114.1, a parser generator for Common Lisp.foxfair2003-10-034-0/+52 * DOM Level 2 Core API for XML based on gdome2.se2003-10-035-0/+91 * Assume maintainership of thoses ports I just addedmat2003-10-023-15/+3 * Add p5-XML-LibXML-Iterator 1.00,mat2003-10-025-0/+46 * Add p5-XML-NodeFilter 0.01,mat2003-10-025-0/+42 * Add p5-XML-LibXML-XPathContext 0.04,mat2003-10-015-0/+50 * Update to 0.39.znerd2003-10-013-6/+6 * Add patch-configure, install static library, bump PORTREVISION.lofi2003-10-013-1/+14 * Replace --program-transform-name with a dependency on gnometarget.lofi2003-09-301-2/+2 * Add ruby-wordnet, a Ruby interface to the WordNet(R) Lexical Database.knu2003-09-295-0/+265 * Update to 0.9.0.knu2003-09-292-3/+2 * Add ruby-rwv2, a Ruby extension that wraps around wv2.knu2003-09-295-0/+52 * The story behind this update:edwin2003-09-293-8/+9 * Update to 0.64.knu2003-09-293-4/+11 * Update to 1.2.2.knu2003-09-292-4/+3 * Update sary to 1.1.0 and ruby-sary to 0.5.knu2003-09-2910-26/+184 * Upgrade to 1.62.3.des2003-09-293-3/+69 * o Update to 0.5.18lioux2003-09-284-9/+15 * - Update to version 3.2krion2003-09-284-37/+13 * New Port: Portable Perl-Compatible Regexps for Common Lisp (SBCL Binaries)edwin2003-09-284-0/+58 * New Port: Portable Perl-Compatible Regexps for Common Lisp (CMUCL Binaries)edwin2003-09-284-0/+58 * New Port: Common Lisp Parser Generator (SBCL Binaries)edwin2003-09-284-0/+53 * New Port: Parser Generator for Common Lisp (CMUCL Binaries)edwin2003-09-284-0/+53 * New Port: Portable Perl-Compatible Regexps for Common Lispedwin2003-09-286-0/+111 * New Port: Common Lisp Parser Generatoredwin2003-09-285-0/+57 * KATO mega patchedwin2003-09-272-10/+10 * Chase print/pdflib version bumpedwin2003-09-271-1/+1 * Add wv2, a library providing routines to access Microsoft Word/Excel files.lofi2003-09-275-0/+66 * - Update to version 0.8.5krion2003-09-254-30/+5 * Fix package building on perl 5.005_03.skv2003-09-251-2/+1 * Update to 0.2.znerd2003-09-252-2/+2 * Add libcroco-0.3.0.adamw2003-09-256-0/+92 * - Update to 0.26.0bland2003-09-256-8/+8 * update to 2.0d10 and fix fetch problem.leeym2003-09-253-2/+5 * - Update to version 0.9.14krion2003-09-2410-32/+70 * - Update to version 1.0.0krion2003-09-246-8/+6 * Update to 0.8.10:netchild2003-09-243-3/+4 * Make portlint(1) happy by changing strip to ${STRIP_CMD}osa2003-09-244-5/+5 * Update to GNOME 2.4.0. For all the goodies on what's changed, known issues,marcus2003-09-188-25/+34 * Conditionalise dependencies on databases/p5-DBI: for perlerwin2003-09-161-3/+12 * Update to 2.03mat2003-09-103-4/+14 * Add ruby-quixml, a Fast XML API for Ruby written in C.knu2003-09-105-0/+59 * Updated to 0.02skv2003-09-094-14/+13 * Updated to 0.02skv2003-09-084-18/+13 * Update to 0.5.17lioux2003-09-083-27/+74 * PR: 56532foxfair2003-09-071-2/+2 * PR: 56531foxfair2003-09-071-10/+9 * Update to 0.6.14.knu2003-09-072-2/+2 * Add p5-XML-RSS-Parser v0.21, A liberal parser for RSS Feeds.foxfair2003-09-065-0/+43 * Chase repocopies towards ports/dnsedwin2003-09-051-1/+1 * Fix build on perl 5.005_03erwin2003-09-054-1/+31 * Updated to 1.0skv2003-09-032-2/+2 * fix plist (add missed PI.pod)skv2003-09-021-0/+1 * Updated to 1.56skv2003-09-022-7/+7 * Upgrade to 2.34.kuriyama2003-09-023-38/+49 * Import p5-XML-SimpleObject-LibXML, Perl extension allowing a simple(r)foxfair2003-09-025-0/+40 * PR: 56163foxfair2003-09-023-4/+10 * Upgrade to 0.13foxfair2003-09-022-2/+2 * Add proper RUN_DEPENDS on "erl".olgeni2003-09-021-0/+1 * - Update to version 0.9.13krion2003-09-028-150/+48 * Add a missed dependency and then bump PORTREVISION.foxfair2003-09-011-1/+3 * - don't clobber any given LDFLAGSdinoex2003-09-012-4/+4 * Add uim, an input method library.nobutaka2003-08-319-0/+195 * Updated to 0.42skv2003-08-312-2/+2 * Updated to 1.24skv2003-08-318-224/+4 * Update port: textproc/jing to 2003.06.19 (unbreak)edwin2003-08-313-14/+239 * [PATCH] textproc/tth: enable choose of ghostscript interpreteredwin2003-08-311-1/+15 * [PATCH] textproc/prosper: enable choose of ghostscript interpreteredwin2003-08-311-1/+15 * [PATCH] textproc/latex2html: enable choose of ghostscript interpreteredwin2003-08-311-1/+18 * PR:foxfair2003-08-293-9/+2 * PR:foxfair2003-08-292-4/+2 * Add p5-XML-Filter-GenericChunk 0.06,erwin2003-08-295-0/+55 * - use new hook USE_GNUSTEP in bsd.port.mkdinoex2003-08-281-6/+3 * - Update to version 0.9.12krion2003-08-284-4/+4 * * Fix Xtract-Bug: s/&/ &amp; / found by blackend.obraun2003-08-286-184/+252 * Bump the PORTREVISION for the ports directly affected by the gettext upgrade.marcus2003-08-277-4/+7 * Update to -> 1.6.5mich2003-08-262-2/+2 * Update to 1.0.4.knu2003-08-262-2/+2 * Chase the libintl.so shared lib version.marcus2003-08-257-7/+7 * From the maintainer:edwin2003-08-251-2/+2 * New port: xalan-c v. 1.4 (XSLT engine and XPath implementation)edwin2003-08-249-0/+4905 * iMAINTAINER-UPDATE: textproc/xerces-c2edwin2003-08-2315-354/+504 * Update to version 1.61.gerald2003-08-232-2/+2 * - Update to version 0.4.3krion2003-08-232-4/+3 * update textproc/gauche-sxml: add 'scheme' virtual catagorydaichi2003-08-211-1/+1 * Update to 0.97mat2003-08-202-2/+2 * update textproc/dictionary: 1.8.3 -> 1.8.5daichi2003-08-202-2/+2 * o Remove mis-addedd $PKGNAMEPREFIX.kuriyama2003-08-193-1/+23 * Connect polish to the buildarved2003-08-193-24/+0 * Add openfts-0.34, a Open Source Full Text Search engine.kuriyama2003-08-195-0/+100 * o Main modificationnork2003-08-191-2/+2 * Update to 0.45erwin2003-08-183-8/+8 * Update to 0.2.9leeym2003-08-182-2/+2 * Fix build on -current.petef2003-08-185-4/+69 * Fix build with gcc 3.3kris2003-08-172-6/+14 * Update my ports to use my @FreeBSD.org addressmat2003-08-16