12#ifndef T_MAIN_GREENLET_CPP
13#define T_MAIN_GREENLET_CPP
15#include "TGreenlet.hpp"
24static std::atomic<Py_ssize_t> G_TOTAL_MAIN_GREENLETS(0);
27static Py_ssize_t G_TOTAL_MAIN_GREENLETS;
33void* MainGreenlet::operator
new(
size_t UNUSED(count))
35 return allocator.allocate(1);
39void MainGreenlet::operator
delete(
void* ptr)
41 return allocator.deallocate(
static_cast<MainGreenlet*
>(ptr),
46MainGreenlet::MainGreenlet(
PyGreenlet* p, ThreadState* state)
51 G_TOTAL_MAIN_GREENLETS++;
54MainGreenlet::~MainGreenlet()
56 G_TOTAL_MAIN_GREENLETS--;
61MainGreenlet::thread_state() const noexcept
63 return this->_thread_state;
67MainGreenlet::thread_state(ThreadState* t)
noexcept
70 this->_thread_state = t;
74const BorrowedMainGreenlet
75MainGreenlet::main_greenlet()
const
81MainGreenlet::find_main_greenlet_in_lineage()
const
83 return BorrowedMainGreenlet(this->_self);
87MainGreenlet::was_running_in_dead_thread() const noexcept
89 return !this->_thread_state;
93MainGreenlet::g_switch()
96 this->check_switch_allowed();
98 catch (
const PyErrOccurred&) {
103 switchstack_result_t err = this->g_switchstack();
104 if (err.status < 0) {
107 return this->on_switchstack_or_initialstub_failure(
115 return err.the_new_current_greenlet->g_switch_finish(err);
119MainGreenlet::tp_traverse(visitproc visit,
void* arg)
121 if (this->_thread_state) {
123 int result = this->_thread_state->tp_traverse(visit, arg,
false);
128 return Greenlet::tp_traverse(visit, arg);
132MainGreenlet::run()
const
134 throw AttributeError(
"Main greenlets do not have a run attribute.");
138MainGreenlet::run(
const BorrowedObject UNUSED(nrun))
140 throw AttributeError(
"Main greenlets do not have a run attribute.");
144MainGreenlet::parent(
const BorrowedObject raw_new_parent)
146 if (!raw_new_parent) {
147 throw AttributeError(
"can't delete attribute");
149 throw AttributeError(
"cannot set the parent of a main greenlet");
153MainGreenlet::parent()
const
155 return OwnedGreenlet();
int make_main(Sequence[str] argv)
Definition build.py:291
Definition greenlet_allocator.hpp:17