diff options
author | xuecai <bluesnow1st@sina.com> | 2019-02-04 03:16:39 +0800 |
---|---|---|
committer | Erik Dubbelboer <erik@dubbelboer.com> | 2019-02-03 19:16:39 +0000 |
commit | 627d63dd25bce25772a610342afd632238463c33 (patch) | |
tree | 22cbf9f70eb9310f7d07e7d829789bbe317396be /timer.go | |
parent | Make InmemoryListener.Dial return when the connection is accepted (diff) | |
download | fasthttp-627d63dd25bce25772a610342afd632238463c33.tar.gz fasthttp-627d63dd25bce25772a610342afd632238463c33.tar.bz2 fasthttp-627d63dd25bce25772a610342afd632238463c33.zip |
* change acquireTimer and releaseTimer to public api
Diffstat (limited to 'timer.go')
-rw-r--r-- | timer.go | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -26,7 +26,12 @@ func stopTimer(t *time.Timer) { } } -func acquireTimer(timeout time.Duration) *time.Timer { +// AcquireTimer returns a time.Timer from the pool and updates it to +// send the current time on its channel after at least timeout. +// +// The returned Timer may be returned to the pool with ReleaseTimer +// when no longer needed. This allows reducing GC load. +func AcquireTimer(timeout time.Duration) *time.Timer { v := timerPool.Get() if v == nil { return time.NewTimer(timeout) @@ -36,7 +41,12 @@ func acquireTimer(timeout time.Duration) *time.Timer { return t } -func releaseTimer(t *time.Timer) { +// ReleaseTimer returns the time.Timer acquired via AcquireTimer to the pool +// and prevents the Timer from firing. +// +// Do not access the released time.Timer or read from it's channel otherwise +// data races may occur. +func ReleaseTimer(t *time.Timer) { stopTimer(t) timerPool.Put(t) } |