Commit 82c402a6 authored by Marius Wachtler's avatar Marius Wachtler Committed by GitHub

Merge pull request #1306 from undingen/generator_opt

generator optimizations
parents 99719a45 d9b5310f
...@@ -83,24 +83,6 @@ private: ...@@ -83,24 +83,6 @@ private:
public: public:
void* stack_start; void* stack_start;
struct StackInfo {
BoxedGenerator* next_generator;
void* stack_start;
void* stack_limit;
StackInfo(BoxedGenerator* next_generator, void* stack_start, void* stack_limit)
: next_generator(next_generator), stack_start(stack_start), stack_limit(stack_limit) {
#if STACK_GROWS_DOWN
assert(stack_start > stack_limit);
assert((char*)stack_start - (char*)stack_limit < (1L << 30));
#else
assert(stack_start < stack_limit);
assert((char*)stack_limit - (char*)stack_start < (1L << 30));
#endif
}
};
std::vector<StackInfo> previous_stacks;
pthread_t pthread_id; pthread_t pthread_id;
PyThreadState* public_thread_state; PyThreadState* public_thread_state;
...@@ -137,36 +119,10 @@ public: ...@@ -137,36 +119,10 @@ public:
} }
ucontext_t* getContext() { return &ucontext; } ucontext_t* getContext() { return &ucontext; }
void pushGenerator(BoxedGenerator* g, void* new_stack_start, void* old_stack_limit) {
previous_stacks.emplace_back(g, this->stack_start, old_stack_limit);
this->stack_start = new_stack_start;
}
void popGenerator() {
assert(previous_stacks.size());
StackInfo& stack = previous_stacks.back();
stack_start = stack.stack_start;
previous_stacks.pop_back();
}
void assertNoGenerators() { assert(previous_stacks.size() == 0); }
}; };
static std::unordered_map<pthread_t, ThreadStateInternal*> current_threads; static std::unordered_map<pthread_t, ThreadStateInternal*> current_threads;
static __thread ThreadStateInternal* current_internal_thread_state = 0; static __thread ThreadStateInternal* current_internal_thread_state = 0;
void pushGenerator(BoxedGenerator* g, void* new_stack_start, void* old_stack_limit) {
assert(new_stack_start);
assert(old_stack_limit);
assert(current_internal_thread_state);
current_internal_thread_state->pushGenerator(g, new_stack_start, old_stack_limit);
}
void popGenerator() {
assert(current_internal_thread_state);
current_internal_thread_state->popGenerator();
}
// These are guarded by threading_lock // These are guarded by threading_lock
static int signals_waiting(0); static int signals_waiting(0);
...@@ -243,8 +199,6 @@ static void tstate_delete_common(PyThreadState* tstate) { ...@@ -243,8 +199,6 @@ static void tstate_delete_common(PyThreadState* tstate) {
} }
static void unregisterThread() { static void unregisterThread() {
current_internal_thread_state->assertNoGenerators();
tstate_delete_common(current_internal_thread_state->public_thread_state); tstate_delete_common(current_internal_thread_state->public_thread_state);
PyThreadState_Clear(current_internal_thread_state->public_thread_state); PyThreadState_Clear(current_internal_thread_state->public_thread_state);
...@@ -438,7 +392,6 @@ static void wait_for_thread_shutdown(void) noexcept { ...@@ -438,7 +392,6 @@ static void wait_for_thread_shutdown(void) noexcept {
void finishMainThread() { void finishMainThread() {
assert(current_internal_thread_state); assert(current_internal_thread_state);
current_internal_thread_state->assertNoGenerators();
wait_for_thread_shutdown(); wait_for_thread_shutdown();
} }
......
...@@ -47,13 +47,6 @@ void finishMainThread(); ...@@ -47,13 +47,6 @@ void finishMainThread();
bool isMainThread(); bool isMainThread();
// Some hooks to keep track of the list of stacks that this thread has been using.
// Every time we switch to a new generator, we need to pass a reference to the generator
// itself (so we can access the registers it is saving), the location of the new stack, and
// where we stopped executing on the old stack.
void pushGenerator(BoxedGenerator* g, void* new_stack_start, void* old_stack_limit);
void popGenerator();
#ifndef THREADING_USE_GIL #ifndef THREADING_USE_GIL
#define THREADING_USE_GIL 1 #define THREADING_USE_GIL 1
#define THREADING_USE_GRWL 0 #define THREADING_USE_GRWL 0
......
This diff is collapsed.
...@@ -26,7 +26,7 @@ struct Context; ...@@ -26,7 +26,7 @@ struct Context;
extern BoxedClass* generator_cls; extern BoxedClass* generator_cls;
void setupGenerator(); void setupGenerator();
void generatorEntry(BoxedGenerator* g); void generatorEntry(BoxedGenerator* g) noexcept;
Context* getReturnContextForGeneratorFrame(void* frame_addr); Context* getReturnContextForGeneratorFrame(void* frame_addr);
extern "C" Box* yield(BoxedGenerator* obj, STOLEN(Box*) value, llvm::ArrayRef<Box*> live_values = {}); extern "C" Box* yield(BoxedGenerator* obj, STOLEN(Box*) value, llvm::ArrayRef<Box*> live_values = {});
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment