From f6166529caf02c22d0de448b66b4a56f291dae2d Mon Sep 17 00:00:00 2001 From: JunYi Wu <53227298+wujunyi792@users.noreply.github.com> Date: Thu, 26 Dec 2024 21:14:00 +0800 Subject: [PATCH] optimize: add global descriptor release api (#249) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 吴骏逸 --- thrift_reflection/descriptor_register.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/thrift_reflection/descriptor_register.go b/thrift_reflection/descriptor_register.go index 47046d8..eeec033 100644 --- a/thrift_reflection/descriptor_register.go +++ b/thrift_reflection/descriptor_register.go @@ -227,6 +227,21 @@ func RegisterAST(ast *parser.Thrift) (*GlobalDescriptor, *FileDescriptor) { return gd, fd } +// ReleaseGlobalDescriptors release the global descriptor +func ReleaseGlobalDescriptors(gds ...*GlobalDescriptor) { + if len(gds) == 0 { + return + } + lock.Lock() + defer lock.Unlock() + for _, gd := range gds { + if gd == nil { + continue + } + delete(globalDescriptorMap, gd.uuid) + } +} + func generateShortUUID() string { uuid := make([]byte, 4) _, _ = rand.Read(uuid)