diff --git a/coverage/ctracer/tracer.c b/coverage/ctracer/tracer.c index c05dff643..18dcb815b 100644 --- a/coverage/ctracer/tracer.c +++ b/coverage/ctracer/tracer.c @@ -982,8 +982,8 @@ static PyObject * CTracer_start(CTracer *self, PyObject *args_unused) { PyEval_SetTrace((Py_tracefunc)CTracer_trace, (PyObject*)self); - self->started = TRUE; self->tracing_arcs = self->trace_arcs && PyObject_IsTrue(self->trace_arcs); + atomic_store(&self->started, TRUE); /* start() returns a trace function usable with sys.settrace() */ Py_INCREF(self); @@ -993,13 +993,11 @@ CTracer_start(CTracer *self, PyObject *args_unused) static PyObject * CTracer_stop(CTracer *self, PyObject *args_unused) { - if (self->started) { - /* Set the started flag only. The actual call to - PyEval_SetTrace(NULL, NULL) is delegated to the callback - itself to ensure that it called from the right thread. - */ - self->started = FALSE; - } + /* Set the started flag only. The actual call to + PyEval_SetTrace(NULL, NULL) is delegated to the callback + itself to ensure that it called from the right thread. + */ + atomic_store(&self->started, FALSE); Py_RETURN_NONE; } diff --git a/coverage/ctracer/tracer.h b/coverage/ctracer/tracer.h index b00134de9..9db97a677 100644 --- a/coverage/ctracer/tracer.h +++ b/coverage/ctracer/tracer.h @@ -32,7 +32,7 @@ typedef struct CTracer { PyObject * disable_plugin; /* Has the tracer been started? */ - BOOL started; + _Atomic BOOL started; /* Are we tracing arcs, or just lines? */ BOOL tracing_arcs; /* Have we had any activity? */ diff --git a/coverage/ctracer/util.h b/coverage/ctracer/util.h index 94591e0d2..cef8e0c4d 100644 --- a/coverage/ctracer/util.h +++ b/coverage/ctracer/util.h @@ -5,6 +5,7 @@ #define _COVERAGE_UTIL_H #include +#include /* Compile-time debugging helpers */ #undef WHAT_LOG /* Define to log the WHAT params in the trace function. */ diff --git a/setup.py b/setup.py index 92fad6502..45c501adf 100644 --- a/setup.py +++ b/setup.py @@ -155,6 +155,11 @@ def run(self): def build_extension(self, ext): """Wrap `build_extension` with `BuildFailed`.""" + if self.compiler.compiler_type == "msvc": + ext.extra_compile_args = (ext.extra_compile_args or []) + [ + "/std:c11", + "/experimental:c11atomics", + ] try: # Uncomment to test compile failure handling: # raise errors.CCompilerError("OOPS")