blob: 6fe0cd0ce1eb11ca2e7cc977b14c26ff814c7a92 [file] [log] [blame]
Girish Kumare48ec8a2020-08-18 12:28:51 +00001// 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
15package jaeger
16
17import "sync"
18
19// SpanAllocator abstraction of managign span allocations
20type SpanAllocator interface {
21 Get() *Span
22 Put(*Span)
23}
24
25type syncPollSpanAllocator struct {
26 spanPool sync.Pool
27}
28
29func newSyncPollSpanAllocator() SpanAllocator {
30 return &syncPollSpanAllocator{
31 spanPool: sync.Pool{New: func() interface{} {
32 return &Span{}
33 }},
34 }
35}
36
37func (pool *syncPollSpanAllocator) Get() *Span {
38 return pool.spanPool.Get().(*Span)
39}
40
41func (pool *syncPollSpanAllocator) Put(span *Span) {
42 span.reset()
43 pool.spanPool.Put(span)
44}
45
46type simpleSpanAllocator struct{}
47
48func (pool simpleSpanAllocator) Get() *Span {
49 return &Span{}
50}
51
52func (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}