__ __ __ __ _____ _ _ _____ _ _ _ | \/ | \ \ / / | __ \ (_) | | / ____| | | | | | \ / |_ __\ V / | |__) | __ ___ ____ _| |_ ___ | (___ | |__ ___| | | | |\/| | '__|> < | ___/ '__| \ \ / / _` | __/ _ \ \___ \| '_ \ / _ \ | | | | | | |_ / . \ | | | | | |\ V / (_| | || __/ ____) | | | | __/ | | |_| |_|_(_)_/ \_\ |_| |_| |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1 if you need WebShell for Seo everyday contact me on Telegram Telegram Address : @jackleetFor_More_Tools:
/* -*- indent-tabs-mode: nil; tab-width: 4; -*- */
/**
* Implementation of GreenletGlobals.
*
* Format with:
* clang-format -i --style=file src/greenlet/greenlet.c
*
*
* Fix missing braces with:
* clang-tidy src/greenlet/greenlet.c -fix -checks="readability-braces-around-statements"
*/
#ifndef T_GREENLET_GLOBALS
#define T_GREENLET_GLOBALS
#include <algorithm>
#include "greenlet_refs.hpp"
#include "greenlet_exceptions.hpp"
#include "greenlet_thread_support.hpp"
#include "greenlet_internal.hpp"
namespace greenlet {
// This encapsulates what were previously module global "constants"
// established at init time.
// This is a step towards Python3 style module state that allows
// reloading.
//
// In an earlier iteration of this code, we used placement new to be
// able to allocate this object statically still, so that references
// to its members don't incur an extra pointer indirection.
// But under some scenarios, that could result in crashes at
// shutdown because apparently the destructor was getting run twice?
class GreenletGlobals
{
public:
const greenlet::refs::ImmortalEventName event_switch;
const greenlet::refs::ImmortalEventName event_throw;
const greenlet::refs::ImmortalException PyExc_GreenletError;
const greenlet::refs::ImmortalException PyExc_GreenletExit;
const greenlet::refs::ImmortalObject empty_tuple;
const greenlet::refs::ImmortalObject empty_dict;
const greenlet::refs::ImmortalString str_run;
Mutex* const thread_states_to_destroy_lock;
greenlet::cleanup_queue_t thread_states_to_destroy;
GreenletGlobals() :
event_switch("switch"),
event_throw("throw"),
PyExc_GreenletError("greenlet.error"),
PyExc_GreenletExit("greenlet.GreenletExit", PyExc_BaseException),
empty_tuple(Require(PyTuple_New(0))),
empty_dict(Require(PyDict_New())),
str_run("run"),
thread_states_to_destroy_lock(new Mutex())
{}
~GreenletGlobals()
{
// This object is (currently) effectively immortal, and not
// just because of those placement new tricks; if we try to
// deallocate the static object we allocated, and overwrote,
// we would be doing so at C++ teardown time, which is after
// the final Python GIL is released, and we can't use the API
// then.
// (The members will still be destructed, but they also don't
// do any deallocation.)
}
/**
* Must be holding the ``thread_states_to_destroy`` lock.
*/
void queue_to_destroy(ThreadState* ts) const
{
// we're currently accessed through a static const object,
// implicitly marking our members as const, so code can't just
// call push_back (or pop_back) without casting away the
// const.
//
// Do that for callers.
greenlet::cleanup_queue_t& q = const_cast<greenlet::cleanup_queue_t&>(
this->thread_states_to_destroy);
// make sure we don't ever try to clean up a state more than
// once. Because they're thread-local, and we ultimately call this
// method from the destructor of the thread local variable,
// we should never find the item already present. This check
// is nominally O(n) in the size of the vector.
assert(std::find(q.begin(), q.end(), ts) == q.end());
q.push_back(ts);
}
/**
* Must be holding the ``thread_states_to_destroy`` lock.
*/
ThreadState* take_next_to_destroy() const
{
greenlet::cleanup_queue_t& q = const_cast<greenlet::cleanup_queue_t&>(
this->thread_states_to_destroy);
if (q.empty()) {
return nullptr;
}
ThreadState* result = q.back();
q.pop_back();
return result;
}
};
}; // namespace greenlet
static const greenlet::GreenletGlobals* mod_globs;
#endif // T_GREENLET_GLOBALS
| Name | Type | Size | Permission | Actions |
|---|---|---|---|---|
| __pycache__ | Folder | 0755 |
|
|
| platform | Folder | 0755 |
|
|
| tests | Folder | 0755 |
|
|
| CObjects.cpp | File | 3.57 KB | 0644 |
|
| PyGreenlet.cpp | File | 27.52 KB | 0644 |
|
| PyGreenlet.hpp | File | 1.43 KB | 0644 |
|
| PyGreenletUnswitchable.cpp | File | 4.06 KB | 0644 |
|
| PyModule.cpp | File | 8.59 KB | 0644 |
|
| TBrokenGreenlet.cpp | File | 1021 B | 0644 |
|
| TExceptionState.cpp | File | 1.33 KB | 0644 |
|
| TGreenlet.cpp | File | 25.62 KB | 0644 |
|
| TGreenlet.hpp | File | 28.58 KB | 0644 |
|
| TGreenletGlobals.cpp | File | 3.84 KB | 0644 |
|
| TMainGreenlet.cpp | File | 3.51 KB | 0644 |
|
| TPythonState.cpp | File | 19.15 KB | 0644 |
|
| TStackState.cpp | File | 7.21 KB | 0644 |
|
| TThreadState.hpp | File | 23.34 KB | 0644 |
|
| TThreadStateCreator.hpp | File | 2.7 KB | 0644 |
|
| TThreadStateDestroy.cpp | File | 7.99 KB | 0644 |
|
| TUserGreenlet.cpp | File | 23.76 KB | 0644 |
|
| __init__.py | File | 1.41 KB | 0644 |
|
| _greenlet.cpython-312-x86_64-linux-gnu.so | File | 1.32 MB | 0755 |
|
| greenlet.cpp | File | 10.83 KB | 0644 |
|
| greenlet.h | File | 4.64 KB | 0644 |
|
| greenlet_allocator.hpp | File | 1.79 KB | 0644 |
|
| greenlet_compiler_compat.hpp | File | 4.24 KB | 0644 |
|
| greenlet_cpython_compat.hpp | File | 3.25 KB | 0644 |
|
| greenlet_exceptions.hpp | File | 4.4 KB | 0644 |
|
| greenlet_internal.hpp | File | 2.7 KB | 0644 |
|
| greenlet_msvc_compat.hpp | File | 3.12 KB | 0644 |
|
| greenlet_refs.hpp | File | 37.17 KB | 0644 |
|
| greenlet_slp_switch.hpp | File | 3.22 KB | 0644 |
|
| greenlet_thread_support.hpp | File | 867 B | 0644 |
|
| slp_platformselect.h | File | 3.87 KB | 0644 |
|