Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends | List of all members
greenlet::Greenlet Class Referenceabstract
Inheritance diagram for greenlet::Greenlet:
Inheritance graph
[legend]
Collaboration diagram for greenlet::Greenlet:
Collaboration graph
[legend]

Classes

class  GreenletStartedWhileInPython
 
struct  switchstack_result_t
 
class  TracingGuard
 

Public Member Functions

 Greenlet (PyGreenlet *p)
 
const OwnedObject context () const
 
void may_switch_away ()
 
void context (refs::BorrowedObject new_context)
 
SwitchingArgsargs ()
 
virtual const refs::BorrowedMainGreenlet main_greenlet () const =0
 
intptr_t stack_saved () const noexcept
 
const char * stack_start () const noexcept
 
virtual OwnedObject throw_GreenletExit_during_dealloc (const ThreadState &current_thread_state)
 
virtual OwnedObject g_switch ()=0
 
virtual void murder_in_place ()
 
void deactivate_and_free ()
 
void deallocing_greenlet_in_thread (const ThreadState *current_state)
 
void expose_frames ()
 
void slp_restore_state () noexcept
 
int slp_save_state (char *const stackref) noexcept
 
bool is_currently_running_in_some_thread () const
 
virtual bool belongs_to_thread (const ThreadState *state) const
 
bool started () const
 
bool active () const
 
bool main () const
 
virtual refs::BorrowedMainGreenlet find_main_greenlet_in_lineage () const =0
 
virtual const OwnedGreenlet parent () const =0
 
virtual void parent (const refs::BorrowedObject new_parent)=0
 
const PythonState::OwnedFrametop_frame ()
 
virtual const OwnedObject & run () const =0
 
virtual void run (const refs::BorrowedObject nrun)=0
 
virtual int tp_traverse (visitproc visit, void *arg)
 
virtual int tp_clear ()
 
virtual ThreadStatethread_state () const noexcept=0
 
virtual bool was_running_in_dead_thread () const noexcept=0
 
BorrowedGreenlet self () const noexcept
 
virtual bool force_slp_switch_error () const noexcept
 

Protected Member Functions

 Greenlet (PyGreenlet *p, const StackState &initial_state)
 
void release_args ()
 
OwnedObject on_switchstack_or_initialstub_failure (Greenlet *target, const switchstack_result_t &err, const bool target_was_me=false, const bool was_initial_stub=false)
 
virtual OwnedGreenlet g_switchstack_success () noexcept
 
void check_switch_allowed () const
 
virtual switchstack_result_t g_switchstack (void)
 

Static Protected Member Functions

static void g_calltrace (const OwnedObject &tracefunc, const greenlet::refs::ImmortalEventName &event, const greenlet::refs::BorrowedGreenlet &origin, const BorrowedGreenlet &target)
 

Protected Attributes

ExceptionState exception_state
 
SwitchingArgs switch_args
 
StackState stack_state
 
PythonState python_state
 

Friends

class ThreadState
 
class UserGreenlet
 
class MainGreenlet
 

Member Function Documentation

◆ deactivate_and_free()

void greenlet::Greenlet::deactivate_and_free ( )
inline

Called when somebody notices we were running in a dead thread to allow cleaning up resources (because we can't raise GreenletExit into it anymore). This is very similar to murder_in_place(), except that it DOES NOT lose the main greenlet or thread state.

◆ g_switchstack()

Greenlet::switchstack_result_t greenlet::Greenlet::g_switchstack ( void  )
protectedvirtual

Perform a stack switch into this greenlet.

This temporarily sets the global variable switching_thread_state to this greenlet; as soon as the call to slp_switch completes, this is reset to NULL. Consequently, this depends on the GIL.

TODO: Adopt the stackman model and pass slp_switch a callback function and context pointer; this eliminates the need for global variables altogether.

Because the stack switch happens in this function, this function can't use its own stack (local) variables, set before the switch, and then accessed after the switch.

Further, you con't even access g_thread_state_global before and after the switch from the global variable. Because it is thread local some compilers cache it in a register/on the stack, notably new versions of MSVC; this breaks with strange crashes sometime later, because writing to anything in g_thread_state_global after the switch is actually writing to random memory. For this reason, we call a non-inlined function to finish the operation. (XXX: The /GT MSVC compiler argument probably fixes that.)

It is very important that stack switch is 'atomic', i.e. no calls into other Python code allowed (except very few that are safe), because global variables are very fragile. (This should no longer be the case with thread-local variables.)

Reimplemented in greenlet::BrokenGreenlet.

◆ murder_in_place()

void greenlet::Greenlet::murder_in_place ( )
virtual

Force the greenlet to appear dead. Used when it's not possible to throw an exception into a greenlet anymore.

This losses access to the thread state and the main greenlet.

Reimplemented in greenlet::UserGreenlet.

◆ on_switchstack_or_initialstub_failure()

OwnedObject greenlet::Greenlet::on_switchstack_or_initialstub_failure ( Greenlet target,
const switchstack_result_t err,
const bool  target_was_me = false,
const bool  was_initial_stub = false 
)
protected

CAUTION: This will allocate memory and may trigger garbage collection and arbitrary Python code.

◆ throw_GreenletExit_during_dealloc()

OwnedObject greenlet::Greenlet::throw_GreenletExit_during_dealloc ( const ThreadState current_thread_state)
virtual

CAUTION: This will allocate memory and may trigger garbage collection and arbitrary Python code.

Reimplemented in greenlet::UserGreenlet.


The documentation for this class was generated from the following files: