Skip to content

Commit b191f58

Browse files
committed
output: add comments for 995e6ba
Signed-off-by: Zero King <[email protected]>
1 parent 995e6ba commit b191f58

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

output/output.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,14 @@ func FLBPluginConfigKey(plugin unsafe.Pointer, key string) string {
7272
var contexts = make(map[uintptr]interface{})
7373

7474
func FLBPluginSetContext(plugin unsafe.Pointer, ctx interface{}) {
75+
// Allocate a byte of memory in the C heap and fill it with '\0',
76+
// then convert its pointer into the C type void*, represented by unsafe.Pointer.
77+
// The C string is not managed by Go GC, so it will not be freed automatically.
7578
i := unsafe.Pointer(C.CString(""))
79+
// uintptr(i) produces the memory address of i, and malloc() guarantees uniqueness of it.
80+
//
81+
// FLBPluginSetContext must not be called concurrently with itself or FLBPluginGetContext.
82+
// A sync.RWMutex must be added if this might happen.
7683
contexts[uintptr(i)] = ctx
7784
p := (*FLBOutPlugin)(plugin)
7885
p.context.remote_context = i

0 commit comments

Comments
 (0)