Girish Kumar | e48ec8a | 2020-08-18 12:28:51 +0000 | [diff] [blame] | 1 | // Copyright (c) 2019 The Jaeger Authors. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package jaeger |
| 16 | |
| 17 | import "sync" |
| 18 | |
| 19 | // SpanAllocator abstraction of managign span allocations |
| 20 | type SpanAllocator interface { |
| 21 | Get() *Span |
| 22 | Put(*Span) |
| 23 | } |
| 24 | |
| 25 | type syncPollSpanAllocator struct { |
| 26 | spanPool sync.Pool |
| 27 | } |
| 28 | |
| 29 | func newSyncPollSpanAllocator() SpanAllocator { |
| 30 | return &syncPollSpanAllocator{ |
| 31 | spanPool: sync.Pool{New: func() interface{} { |
| 32 | return &Span{} |
| 33 | }}, |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func (pool *syncPollSpanAllocator) Get() *Span { |
| 38 | return pool.spanPool.Get().(*Span) |
| 39 | } |
| 40 | |
| 41 | func (pool *syncPollSpanAllocator) Put(span *Span) { |
| 42 | span.reset() |
| 43 | pool.spanPool.Put(span) |
| 44 | } |
| 45 | |
| 46 | type simpleSpanAllocator struct{} |
| 47 | |
| 48 | func (pool simpleSpanAllocator) Get() *Span { |
| 49 | return &Span{} |
| 50 | } |
| 51 | |
| 52 | func (pool simpleSpanAllocator) Put(span *Span) { |
| 53 | // @comment https://github.com/jaegertracing/jaeger-client-go/pull/381#issuecomment-475904351 |
| 54 | // since finished spans are not reused, no need to reset them |
| 55 | // span.reset() |
| 56 | } |