From 561db30e03d5cf22709c8dbf091c5ea61717695e Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Fri, 21 Mar 2025 21:12:36 +0800 Subject: [PATCH] gpool: Generic wrapper for sync.Pool --- README.md | 9 +++++---- gpool/LICENSE | 1 + gpool/pool.go | 16 ++++++++++++++++ diff --git a/README.md b/README.md index 0a49657ee583799a057f0b19d23e67e79836d61b..d20b20dc6b792a3a657d97f2523fde94af3b2e79 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,11 @@ This needs to be addressed in the future. ## Ported/forked packages -| Name | Description | Origin | License | -| - | - | - | - | -| scfg | Configuration parsing library | emersion | MIT | -| cmap | Generic concurrent maps | Go | BSD-3-Clause | +| Name | Description | Origin | License | +| - | - | - | - | +| scfg | Configuration parsing library | emersion | MIT | +| cmap | Generic concurrent maps | Go | BSD-3-Clause | +| gpool | Generic wrapper for sync.Pool | Go | BSD-3-Clause | ## Custom packages diff --git a/gpool/LICENSE b/gpool/LICENSE new file mode 120000 index 0000000000000000000000000000000000000000..97a673a14c09b79e98e8b8aad4c965a1ca5a396c --- /dev/null +++ b/gpool/LICENSE @@ -0,0 +1 @@ +../LICENSE.3BSD \ No newline at end of file diff --git a/gpool/pool.go b/gpool/pool.go new file mode 100644 index 0000000000000000000000000000000000000000..9959b0d23e5b3d5691e6b7a4e921e2fac4344669 --- /dev/null +++ b/gpool/pool.go @@ -0,0 +1,16 @@ +package gpool + +import "sync" + +type Pool[T any] struct { + p sync.Pool + New func() T +} + +func (p *Pool[T]) Get() T { + return p.p.Get().(T) +} + +func (p *Pool[T]) Put(x T) { + p.p.Put(x) +} -- 2.48.1