From 6d293ce152d4b301e029738cbd9375470dbd221d Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 24 Sep 2014 21:31:26 +0800 Subject: [PATCH] use async notify --- server/cmd_replication.go | 5 +---- server/replication.go | 17 +++++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/server/cmd_replication.go b/server/cmd_replication.go index 1433143..a261f42 100644 --- a/server/cmd_replication.go +++ b/server/cmd_replication.go @@ -83,10 +83,7 @@ func syncCommand(c *client) error { c.lastLogID = logId - 1 if c.ack != nil && logId > c.ack.id { - select { - case c.ack.ch <- logId: - default: - } + asyncNotifyUint64(c.ack.ch, logId) c.ack = nil } diff --git a/server/replication.go b/server/replication.go index 3616762..d90caab 100644 --- a/server/replication.go +++ b/server/replication.go @@ -54,10 +54,7 @@ func newMaster(app *App) *master { } func (m *master) Close() { - select { - case m.quit <- struct{}{}: - default: - } + ledis.AsyncNotify(m.quit) if m.conn != nil { m.conn.Close() @@ -262,10 +259,14 @@ func (app *App) removeSlave(c *client) { delete(app.slaves, c) if c.ack != nil { - select { - case c.ack.ch <- c.lastLogID: - default: - } + asyncNotifyUint64(c.ack.ch, c.lastLogID) + } +} + +func asyncNotifyUint64(ch chan uint64, v uint64) { + select { + case ch <- v: + default: } }