Commit 40fa7ef7 authored by Marius Wachtler's avatar Marius Wachtler

remove generator pushing code

parent d7fa6e8a
......@@ -83,24 +83,6 @@ private:
public:
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;
PyThreadState* public_thread_state;
......@@ -137,36 +119,10 @@ public:
}
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 __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
static int signals_waiting(0);
......@@ -243,8 +199,6 @@ static void tstate_delete_common(PyThreadState* tstate) {
}
static void unregisterThread() {
current_internal_thread_state->assertNoGenerators();
tstate_delete_common(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 {
void finishMainThread() {
assert(current_internal_thread_state);
current_internal_thread_state->assertNoGenerators();
wait_for_thread_shutdown();
}
......
......@@ -47,13 +47,6 @@ void finishMainThread();
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
#define THREADING_USE_GIL 1
#define THREADING_USE_GRWL 0
......
......@@ -92,7 +92,6 @@ void generatorEntry(BoxedGenerator* g) {
assert(g->returnValue == Py_None);
Py_CLEAR(g->returnValue);
threading::pushGenerator(g, g->stack_begin, g->returnContext);
try {
RegisterHelper context_registerer(g, __builtin_frame_address(0));
......@@ -115,7 +114,6 @@ void generatorEntry(BoxedGenerator* g) {
// we returned from the body of the generator. next/send/throw will notify the caller
g->entryExited = true;
threading::popGenerator();
}
assert(g->top_caller_frame_info == cur_thread_state.frame_info);
swapContext(&g->context, g->returnContext, 0);
......@@ -333,16 +331,15 @@ Box* generatorHasnext(Box* s) {
extern "C" Box* yield_capi(BoxedGenerator* obj, STOLEN(Box*) value, int num_live_values, ...) noexcept {
try {
llvm::SmallVector<Box*, 8> live_values;
live_values.reserve(num_live_values);
Box** live_values = (Box**)alloca(sizeof(Box*) * num_live_values);
va_list ap;
va_start(ap, num_live_values);
for (int i = 0; i < num_live_values; ++i) {
live_values.push_back(va_arg(ap, Box*));
live_values[i] = va_arg(ap, Box*);
}
va_end(ap);
return yield(obj, value, live_values);
return yield(obj, value, llvm::makeArrayRef(live_values, num_live_values));
} catch (ExcInfo e) {
setCAPIException(e);
return NULL;
......@@ -357,8 +354,6 @@ extern "C" Box* yield(BoxedGenerator* obj, STOLEN(Box*) value, llvm::ArrayRef<Bo
assert(!self->returnValue);
self->returnValue = value;
threading::popGenerator();
FrameInfo* generator_frame_info = (FrameInfo*)cur_thread_state.frame_info;
// a generator will only switch back (yield/unhandled exception) to its caller when it is one frame away from the
// caller
......@@ -384,8 +379,6 @@ extern "C" Box* yield(BoxedGenerator* obj, STOLEN(Box*) value, llvm::ArrayRef<Bo
}
cur_thread_state.frame_info = generator_frame_info;
threading::pushGenerator(obj, obj->stack_begin, obj->returnContext);
// if the generator receives a exception from the caller we have to throw it
if (self->exception.type) {
ExcInfo e = self->exception;
......
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