@@ -18,6 +18,10 @@ type Item[T any] struct {
1818 cfg any
1919 // align 64
2020
21+ // id only take effect on issync = True
22+ id int64
23+ // align 64
24+
2125 val T
2226}
2327
@@ -36,7 +40,9 @@ func (b *Item[T]) Trans() T {
3640 panic ("use after destroy" )
3741 }
3842 if b .pool .issync {
39- b .stat .setinsyncop (true )
43+ if ! b .stat .setinsyncop (true ) {
44+ panic ("non-unique op" )
45+ }
4046 }
4147 val := b .val
4248 atomic .StoreUintptr (
@@ -51,7 +57,10 @@ func (b *Item[T]) Trans() T {
5157// and will be Reset on putting back.
5258func (b * Item [T ]) HasInvolved () bool {
5359 if b .pool .issync {
54- b .stat .setinsyncop (true )
60+ if ! b .stat .setinsyncop (true ) && getGoroutineID () != b .id {
61+ panic ("non-unique op" )
62+ }
63+ atomic .StoreInt64 (& b .id , getGoroutineID ())
5564 defer b .stat .setinsyncop (false )
5665 }
5766 return b .stat .isbuffered ()
@@ -65,7 +74,10 @@ func (b *Item[T]) V(f func(T)) {
6574 panic ("use after destroy" )
6675 }
6776 if b .pool .issync {
68- b .stat .setinsyncop (true )
77+ if ! b .stat .setinsyncop (true ) && getGoroutineID () != b .id {
78+ panic ("non-unique op" )
79+ }
80+ atomic .StoreInt64 (& b .id , getGoroutineID ())
6981 defer b .stat .setinsyncop (false )
7082 }
7183 f (b .val )
@@ -80,7 +92,10 @@ func (b *Item[T]) P(f func(*T)) {
8092 panic ("use after destroy" )
8193 }
8294 if b .pool .issync {
83- b .stat .setinsyncop (true )
95+ if ! b .stat .setinsyncop (true ) && getGoroutineID () != b .id {
96+ panic ("non-unique op" )
97+ }
98+ atomic .StoreInt64 (& b .id , getGoroutineID ())
8499 defer b .stat .setinsyncop (false )
85100 }
86101 f (& b .val )
@@ -93,7 +108,10 @@ func (b *Item[T]) Copy() (cb *Item[T]) {
93108 panic ("use after destroy" )
94109 }
95110 if b .pool .issync {
96- b .stat .setinsyncop (true )
111+ if ! b .stat .setinsyncop (true ) && getGoroutineID () != b .id {
112+ panic ("non-unique op" )
113+ }
114+ atomic .StoreInt64 (& b .id , getGoroutineID ())
97115 defer b .stat .setinsyncop (false )
98116 }
99117 cb = b .pool .New (b .cfg )
0 commit comments