Armin Rigo avatar Armin Rigo committed 057d18c

Random progress, but I still didn't find the "correct" way...

Comments (0)

Files changed (4)

pypy/rlib/_rffi_stacklet.py

 thread_handle = rffi.COpaquePtr(typedef='stacklet_thread_handle',
                                 compilation_info=eci)
 run_fn = lltype.Ptr(lltype.FuncType([handle, llmemory.Address], handle))
+id = rffi.COpaquePtr(typedef='stacklet_id', compilation_info=eci)
 
 # ----- constants -----
 
 _translate_pointer = llexternal("_stacklet_translate_pointer",
                                 [llmemory.Address, llmemory.Address],
                                 llmemory.Address)
+_stacklet_with_id = llexternal("_stacklet_with_id", [thread_handle, id],
+                               handle)

pypy/rlib/rstacklet.py

 
     @jit.dont_look_inside
     def __init__(self, config):
+        stacklet_thread_global.enable()
         self._gcrootfinder = _getgcrootfinder(config, we_are_translated())
         self._thrd = _c.newthread()
         if not self._thrd:
             self._thrd = lltype.nullptr(_c.thread_handle.TO)
             _c.deletethread(thrd)
 
+class StackletThreadGlobal(object):
+    _immutable_fields_ = ['enabled?']
+
+    def _freeze_(self):
+        self.enabled = False
+
+    def enable(self):
+        if not self.enabled:
+            self.enabled = True    # change the quasi-immutable field
+
+stacklet_thread_global = StackletThreadGlobal()
+stacklet_thread_global._freeze_()
+
 # ____________________________________________________________
 
 def _getgcrootfinder(config, translated):

pypy/translator/c/src/stacklet/stacklet.c

             break;
         }
     assert(target->id->stacklet == target);
-    free(target->id);
+    if (target->id != &thrd->g_main_id)
+        free(target->id);
     free(target);
 }
 
   }
   return ptr;
 }
-
-stacklet_handle _stacklet_with_id(stacklet_thread_handle thrd, stacklet_id id)
-{
-    if (id == NULL)
-        id = &thrd->g_main_id;
-    return id->stacklet;
-}

pypy/translator/c/src/stacklet/stacklet.h

 #define _stacklet_id_of_stacklet(stacklet) (*(stacklet_id*)(stacklet))
 #define _stacklet_id_current(thrd) (*(stacklet_id*)(thrd))
 /* Returns the current stacklet with the given id.
-   If 'id' == NULL, returns the main stacklet in the thread. */
+   If 'id' == NULL, returns the main stacklet in the thread.
+   In both cases the return value is NULL if the id specifies the currently
+   running "stacklet". */
 stacklet_handle _stacklet_with_id(stacklet_thread_handle thrd, stacklet_id id);
 
 #endif /* _STACKLET_H_ */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.