@@ -818,7 +818,7 @@ CTracer_trace(CTracer *self, PyFrameObject *frame, int what, PyObject *arg_unuse
818
818
return RET_OK ;
819
819
#endif
820
820
821
- if (!self -> started ) {
821
+ if (!atomic_load ( & self -> started ) ) {
822
822
/* If CTracer.stop() has been called from another thread, the tracer
823
823
is still active in the current thread. Let's deactivate ourselves
824
824
now. */
@@ -848,7 +848,7 @@ CTracer_trace(CTracer *self, PyFrameObject *frame, int what, PyObject *arg_unuse
848
848
Py_DECREF (ascii );
849
849
#endif
850
850
851
- self -> activity = TRUE;
851
+ atomic_store ( & self -> activity , TRUE) ;
852
852
853
853
switch (what ) {
854
854
case PyTrace_CALL :
@@ -981,9 +981,10 @@ CTracer_call(CTracer *self, PyObject *args, PyObject *kwds)
981
981
static PyObject *
982
982
CTracer_start (CTracer * self , PyObject * args_unused )
983
983
{
984
+ assert (atomic_load (& self -> started ) == FALSE);
984
985
PyEval_SetTrace ((Py_tracefunc )CTracer_trace , (PyObject * )self );
985
- self -> started = TRUE;
986
986
self -> tracing_arcs = self -> trace_arcs && PyObject_IsTrue (self -> trace_arcs );
987
+ atomic_store (& self -> started , TRUE);
987
988
988
989
/* start() returns a trace function usable with sys.settrace() */
989
990
Py_INCREF (self );
@@ -993,21 +994,19 @@ CTracer_start(CTracer *self, PyObject *args_unused)
993
994
static PyObject *
994
995
CTracer_stop (CTracer * self , PyObject * args_unused )
995
996
{
996
- if (self -> started ) {
997
- /* Set the started flag only. The actual call to
998
- PyEval_SetTrace(NULL, NULL) is delegated to the callback
999
- itself to ensure that it called from the right thread.
1000
- */
1001
- self -> started = FALSE;
1002
- }
997
+ /* Set the started flag only. The actual call to
998
+ PyEval_SetTrace(NULL, NULL) is delegated to the callback
999
+ itself to ensure that it called from the right thread.
1000
+ */
1001
+ atomic_store (& self -> started , FALSE);
1003
1002
1004
1003
Py_RETURN_NONE ;
1005
1004
}
1006
1005
1007
1006
static PyObject *
1008
1007
CTracer_activity (CTracer * self , PyObject * args_unused )
1009
1008
{
1010
- if (self -> activity ) {
1009
+ if (atomic_load ( & self -> activity ) ) {
1011
1010
Py_RETURN_TRUE ;
1012
1011
}
1013
1012
else {
@@ -1018,7 +1017,7 @@ CTracer_activity(CTracer *self, PyObject *args_unused)
1018
1017
static PyObject *
1019
1018
CTracer_reset_activity (CTracer * self , PyObject * args_unused )
1020
1019
{
1021
- self -> activity = FALSE;
1020
+ atomic_store ( & self -> activity , FALSE) ;
1022
1021
Py_RETURN_NONE ;
1023
1022
}
1024
1023
0 commit comments