Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 84d8329

Browse files
author
Anselm Kruis
committed
Stackless issue #149: Remove support for threads-less builds
Implement bpo-31370 for Stackless C-source.
1 parent 067d69d commit 84d8329

File tree

6 files changed

+0
-56
lines changed

6 files changed

+0
-56
lines changed

Python/pystate.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ static PyInterpreterState *autoInterpreterState = NULL;
5454
static int autoTLSkey = -1;
5555

5656
#ifdef STACKLESS
57-
#ifdef WITH_THREAD
5857
void
5958
slp_head_lock(void) {
6059
HEAD_LOCK();
@@ -65,7 +64,6 @@ slp_head_unlock(void) {
6564
HEAD_UNLOCK();
6665
}
6766
#endif
68-
#endif
6967

7068
static PyInterpreterState *interp_head = NULL;
7169
static PyInterpreterState *interp_main = NULL;

Stackless/core/stackless_impl.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -817,15 +817,10 @@ PyObject * slp_get_channel_callback(void);
817817

818818
/* Interpreter shutdown and thread state access */
819819
PyObject * slp_getthreads(PyObject *self);
820-
#ifdef WITH_THREAD
821820
void slp_head_lock(void);
822821
void slp_head_unlock(void);
823822
#define SLP_HEAD_LOCK() slp_head_lock()
824823
#define SLP_HEAD_UNLOCK() slp_head_unlock()
825-
#else
826-
#define SLP_HEAD_LOCK() assert(1)
827-
#define SLP_HEAD_UNLOCK() assert(1)
828-
#endif
829824

830825
long slp_parse_thread_id(PyObject *thread_id, unsigned long *id);
831826

Stackless/core/stackless_tstate.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,11 @@ typedef struct _sts {
4343
long tick_watermark;
4444
long interval;
4545
PyObject * (*interrupt) (void); /* the fast scheduler */
46-
#ifdef WITH_THREAD
4746
struct {
4847
PyObject *block_lock; /* to block the thread */
4948
int is_blocked; /* waiting to be unblocked */
5049
int is_idle; /* unblocked, but waiting for GIL */
5150
} thread;
52-
#endif
5351
PyObject *del_post_switch; /* To decref after a switch */
5452
PyObject *interrupted; /* The interrupted tasklet in stackles.run() */
5553
PyObject *watchdogs; /* the stack of currently running watchdogs */
@@ -121,8 +119,6 @@ void slp_kill_tasks_with_stacks(struct _ts *tstate);
121119
Py_CLEAR(tstate->st.unwinding_retval); \
122120
__STACKLESS_PYSTATE_CLEAR_NEXT_FRAME
123121

124-
#ifdef WITH_THREAD
125-
126122
#define STACKLESS_PYSTATE_NEW \
127123
__STACKLESS_PYSTATE_NEW \
128124
tstate->st.thread.block_lock = NULL; \
@@ -134,10 +130,3 @@ void slp_kill_tasks_with_stacks(struct _ts *tstate);
134130
Py_CLEAR(tstate->st.thread.block_lock); \
135131
tstate->st.thread.is_blocked = 0; \
136132
tstate->st.thread.is_idle = 0;
137-
138-
#else
139-
140-
#define STACKLESS_PYSTATE_NEW __STACKLESS_PYSTATE_NEW
141-
#define STACKLESS_PYSTATE_CLEAR __STACKLESS_PYSTATE_CLEAR
142-
143-
#endif

Stackless/module/scheduling.c

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
#ifdef STACKLESS
44
#include "core/stackless_impl.h"
55

6-
#ifdef WITH_THREAD
76
#include "pythread.h"
8-
#endif
97

108
/******************************************************
119
@@ -673,12 +671,9 @@ slp_ensure_linkage(PyTaskletObject *t)
673671
static int
674672
is_thread_runnable(PyThreadState *ts)
675673
{
676-
#ifdef WITH_THREAD
677674
if (ts == PyThreadState_GET())
678675
return 0;
679676
return !ts->st.thread.is_blocked;
680-
#endif
681-
return 0;
682677
}
683678

684679
static int
@@ -707,8 +702,6 @@ make_deadlock_bomb(void)
707702
return slp_curexc_to_bomb();
708703
}
709704

710-
#ifdef WITH_THREAD
711-
712705
/* make sure that locks live longer than their threads */
713706

714707
static void
@@ -774,13 +767,6 @@ void slp_thread_unblock(PyThreadState *nts)
774767
schedule_thread_unblock(nts);
775768
}
776769

777-
#else
778-
779-
void slp_thread_unblock(PyThreadState *nts)
780-
{}
781-
782-
#endif
783-
784770
static int
785771
schedule_task_block(PyObject **result, PyTaskletObject *prev, int stackless, int *did_switch)
786772
{
@@ -793,19 +779,16 @@ schedule_task_block(PyObject **result, PyTaskletObject *prev, int stackless, int
793779
/* which "main" do we awaken if we are blocking? */
794780
wakeup = slp_get_watchdog(ts, 0);
795781

796-
#ifdef WITH_THREAD
797782
if ( !(ts->st.runflags & Py_WATCHDOG_THREADBLOCK) && wakeup->next == NULL)
798783
/* we also must never block if watchdog is running not in threadblocking mode */
799784
revive_main = 1;
800785

801786
if (revive_main)
802787
assert(wakeup->next == NULL); /* target must be floating */
803-
#endif
804788

805789
if (revive_main || check_for_deadlock()) {
806790
goto cantblock;
807791
}
808-
#ifdef WITH_THREAD
809792
for(;;) {
810793
/* store the frame back in the tasklet while we thread block, so that
811794
* e.g. insert doesn't think that it is dead
@@ -832,10 +815,6 @@ schedule_task_block(PyObject **result, PyTaskletObject *prev, int stackless, int
832815
if (check_for_deadlock())
833816
goto cantblock;
834817
}
835-
#else
836-
next = prev;
837-
Py_INCREF(next);
838-
#endif
839818
/* this must be after releasing the locks because of hard switching */
840819
fail = slp_schedule_task(result, prev, next, stackless, did_switch);
841820
Py_DECREF(next);
@@ -881,7 +860,6 @@ schedule_task_block(PyObject **result, PyTaskletObject *prev, int stackless, int
881860
return fail;
882861
}
883862

884-
#ifdef WITH_THREAD
885863
static int
886864
schedule_task_interthread(PyObject **result,
887865
PyTaskletObject *prev,
@@ -921,8 +899,6 @@ schedule_task_interthread(PyObject **result,
921899
return 0;
922900
}
923901

924-
#endif
925-
926902
/* deal with soft interrupts by modifying next to specify the main tasklet */
927903
static void slp_schedule_soft_irq(PyThreadState *ts, PyTaskletObject *prev,
928904
PyTaskletObject **next, int not_now)
@@ -993,15 +969,13 @@ slp_schedule_task(PyObject **result, PyTaskletObject *prev, PyTaskletObject *nex
993969
if (next == NULL)
994970
return schedule_task_block(result, prev, stackless, did_switch);
995971

996-
#ifdef WITH_THREAD
997972
/* note that next->cstate is undefined if it is ourself.
998973
Also note, that prev->cstate->tstate == NULL during Py_Finalize() */
999974
assert(prev->cstate == NULL || prev->cstate->tstate == NULL || prev->cstate->tstate == ts);
1000975
/* The last condition is required during shutdown when next->cstate->tstate == NULL */
1001976
if (next->cstate != NULL && next->cstate->tstate != ts && next != prev) {
1002977
return schedule_task_interthread(result, prev, next, stackless, did_switch);
1003978
}
1004-
#endif
1005979

1006980
/* switch trap. We don't trap on interthread switches because they
1007981
* don't cause a switch on the local thread.

Stackless/module/stacklessmodule.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,7 @@ PyDoc_STRVAR(getcurrentid__doc__,
309309
unsigned long
310310
PyStackless_GetCurrentId(void)
311311
{
312-
#ifdef WITH_THREAD
313312
PyThreadState *ts = PyGILState_GetThisThreadState();
314-
#else
315-
PyThreadState *ts = PyThreadState_GET();
316-
#endif
317313
PyTaskletObject *t = NULL;
318314
/* if there is threadstate, and there is a main tasklet, then the
319315
* "current" is the actively running tasklet.
@@ -336,11 +332,7 @@ PyStackless_GetCurrentId(void)
336332
*/
337333
if (ts)
338334
return ts->thread_id;
339-
#ifdef WITH_THREAD
340335
return PyThread_get_thread_ident();
341-
#else
342-
return 0;
343-
#endif
344336
}
345337

346338
static PyObject *

Stackless/module/taskletobject.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,6 @@ impl_tasklet_run_remove(PyTaskletObject *task, int remove)
855855
removed = 1;
856856
}
857857
} else {
858-
#ifdef WITH_THREAD
859858
/* interthread. */
860859
PyThreadState *rts = task->cstate->tstate;
861860
PyTaskletObject *current;
@@ -882,9 +881,6 @@ impl_tasklet_run_remove(PyTaskletObject *task, int remove)
882881
/* remote thread is in a weird state. Just insert it */
883882
fail = impl_tasklet_insert(task);
884883
}
885-
#else
886-
RUNTIME_ERROR("tasklet has an invalid thread.", NULL);
887-
#endif
888884
}
889885
if (fail)
890886
return NULL;

0 commit comments

Comments
 (0)