7474import com .oracle .truffle .api .dsl .Bind ;
7575import com .oracle .truffle .api .dsl .Cached ;
7676import com .oracle .truffle .api .dsl .Cached .Exclusive ;
77+ import com .oracle .truffle .api .dsl .Cached .Shared ;
7778import com .oracle .truffle .api .dsl .GenerateNodeFactory ;
7879import com .oracle .truffle .api .dsl .NodeFactory ;
7980import com .oracle .truffle .api .dsl .Specialization ;
@@ -153,16 +154,16 @@ static Object doNoTimeout(PSimpleQueue self,
153154 @ GenerateNodeFactory
154155 @ ArgumentClinic (name = "block" , conversion = ClinicConversion .Boolean , defaultValue = "true" )
155156 public abstract static class SimpleQueueGetNode extends PythonTernaryClinicBuiltinNode {
156- @ Child private GilNode gil ;
157157
158158 @ Override
159159 protected ArgumentClinicProvider getArgumentClinic () {
160160 return SimpleQueueGetNodeClinicProviderGen .INSTANCE ;
161161 }
162162
163163 @ Specialization (guards = "!withTimeout(block, timeout)" )
164- Object doNoTimeout (PSimpleQueue self , boolean block , @ SuppressWarnings ("unused" ) Object timeout ,
164+ static Object doNoTimeout (PSimpleQueue self , boolean block , @ SuppressWarnings ("unused" ) Object timeout ,
165165 @ Bind ("this" ) Node inliningTarget ,
166+ @ Shared @ Cached GilNode gil ,
166167 @ Exclusive @ Cached PRaiseNode .Lazy raiseNode ) {
167168 // CPython first tries a non-blocking get without releasing the GIL
168169 Object result = self .poll ();
@@ -171,25 +172,25 @@ Object doNoTimeout(PSimpleQueue self, boolean block, @SuppressWarnings("unused")
171172 }
172173 if (block ) {
173174 try {
174- ensureGil () .release (true );
175+ gil .release (true );
175176 return self .get ();
176177 } catch (InterruptedException e ) {
177178 CompilerDirectives .transferToInterpreter ();
178179 Thread .currentThread ().interrupt ();
179180 return PNone .NONE ;
180181 } finally {
181- ensureGil () .acquire ();
182+ gil .acquire ();
182183 }
183184 }
184185 throw raiseNode .get (inliningTarget ).raise (Empty );
185186 }
186187
187188 @ Specialization (guards = "withTimeout(block, timeout)" )
188- @ SuppressWarnings ("truffle-static-method" )
189- Object doTimeout (VirtualFrame frame , PSimpleQueue self , boolean block , Object timeout ,
189+ static Object doTimeout (VirtualFrame frame , PSimpleQueue self , boolean block , Object timeout ,
190190 @ Bind ("this" ) Node inliningTarget ,
191191 @ Cached PyLongAsLongAndOverflowNode asLongNode ,
192192 @ Cached CastToJavaDoubleNode castToDouble ,
193+ @ Shared @ Cached GilNode gil ,
193194 @ Exclusive @ Cached PRaiseNode .Lazy raiseNode ) {
194195 assert block ;
195196
@@ -216,7 +217,7 @@ Object doTimeout(VirtualFrame frame, PSimpleQueue self, boolean block, Object ti
216217 }
217218
218219 try {
219- ensureGil () .release (true );
220+ gil .release (true );
220221 result = self .get (ltimeout );
221222 if (result != null ) {
222223 return result ;
@@ -225,19 +226,11 @@ Object doTimeout(VirtualFrame frame, PSimpleQueue self, boolean block, Object ti
225226 CompilerDirectives .transferToInterpreter ();
226227 Thread .currentThread ().interrupt ();
227228 } finally {
228- ensureGil () .acquire ();
229+ gil .acquire ();
229230 }
230231 throw raiseNode .get (inliningTarget ).raise (Empty );
231232 }
232233
233- private GilNode ensureGil () {
234- if (gil == null ) {
235- CompilerDirectives .transferToInterpreterAndInvalidate ();
236- gil = insert (GilNode .create ());
237- }
238- return gil ;
239- }
240-
241234 static boolean withTimeout (boolean block , Object timeout ) {
242235 return block && !(timeout instanceof PNone );
243236 }
0 commit comments