mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 10:48:51 +00:00
THRIFT-3855 Replaced complex CompareAndSwapInt64 with syncOnce.
Client: Go Paul <pavel.finkelshtein@gmail.com> This closes #1094
This commit is contained in:
parent
1ac0a80aa0
commit
2df9c20dc7
@ -22,13 +22,12 @@ package thrift
|
||||
import (
|
||||
"log"
|
||||
"runtime/debug"
|
||||
"sync/atomic"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// Simple, non-concurrent server for testing.
|
||||
type TSimpleServer struct {
|
||||
quit chan struct{}
|
||||
stopped int64
|
||||
|
||||
processorFactory TProcessorFactory
|
||||
serverTransport TServerTransport
|
||||
@ -150,11 +149,14 @@ func (p *TSimpleServer) Serve() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var once sync.Once
|
||||
|
||||
func (p *TSimpleServer) Stop() error {
|
||||
if atomic.CompareAndSwapInt64(&p.stopped, 0, 1) {
|
||||
q := func() {
|
||||
p.quit <- struct{}{}
|
||||
p.serverTransport.Interrupt()
|
||||
}
|
||||
once.Do(q)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -186,7 +188,7 @@ func (p *TSimpleServer) processRequests(client TTransport) error {
|
||||
if err, ok := err.(TApplicationException); ok && err.TypeId() == UNKNOWN_METHOD {
|
||||
continue
|
||||
}
|
||||
if !ok {
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user