| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4b8b86c commit 244e120
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,7 +30,7 @@ typedef enum _Py_memory_order { | |||
| 30 | 30 | } _Py_memory_order; | |
| 31 | 31 | ||
| 32 | 32 | typedef struct _Py_atomic_address { | |
| 33 | - _Atomic void *_value; | ||
| 33 | + atomic_uintptr_t _value; | ||
| 34 | 34 | } _Py_atomic_address; | |
| 35 | 35 | ||
| 36 | 36 | typedef struct _Py_atomic_int { | |
@@ -61,7 +61,7 @@ typedef enum _Py_memory_order { | |||
| 61 | 61 | } _Py_memory_order; | |
| 62 | 62 | ||
| 63 | 63 | typedef struct _Py_atomic_address { | |
| 64 | - void *_value; | ||
| 64 | + Py_uintptr_t _value; | ||
| 65 | 65 | } _Py_atomic_address; | |
| 66 | 66 | ||
| 67 | 67 | typedef struct _Py_atomic_int { | |
@@ -98,7 +98,7 @@ typedef enum _Py_memory_order { | |||
| 98 | 98 | } _Py_memory_order; | |
| 99 | 99 | ||
| 100 | 100 | typedef struct _Py_atomic_address { | |
| 101 | - void *_value; | ||
| 101 | + Py_uintptr_t _value; | ||
| 102 | 102 | } _Py_atomic_address; | |
| 103 | 103 | ||
| 104 | 104 | typedef struct _Py_atomic_int { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,7 +111,7 @@ static _Py_atomic_int gil_locked = {-1}; | |||
| 111 | 111 | static unsigned long gil_switch_number = 0; | |
| 112 | 112 | /* Last PyThreadState holding / having held the GIL. This helps us know | |
| 113 | 113 | whether anyone else was scheduled after we dropped the GIL. */ | |
| 114 | - static _Py_atomic_address gil_last_holder = {NULL}; | ||
| 114 | + static _Py_atomic_address gil_last_holder = {0}; | ||
| 115 | 115 | ||
| 116 | 116 | /* This condition variable allows one or several threads to wait until | |
| 117 | 117 | the GIL is released. In addition, the mutex also protects the above | |
@@ -142,7 +142,7 @@ static void create_gil(void) | |||
| 142 | 142 | #ifdef FORCE_SWITCHING | |
| 143 | 143 | COND_INIT(switch_cond); | |
| 144 | 144 | #endif | |
| 145 | - _Py_atomic_store_relaxed(&gil_last_holder, NULL); | ||
| 145 | + _Py_atomic_store_relaxed(&gil_last_holder, 0); | ||
| 146 | 146 | _Py_ANNOTATE_RWLOCK_CREATE(&gil_locked); | |
| 147 | 147 | _Py_atomic_store_explicit(&gil_locked, 0, _Py_memory_order_release); | |
| 148 | 148 | } | |
@@ -178,7 +178,7 @@ static void drop_gil(PyThreadState *tstate) | |||
| 178 | 178 | /* Sub-interpreter support: threads might have been switched | |
| 179 | 179 | under our feet using PyThreadState_Swap(). Fix the GIL last | |
| 180 | 180 | holder variable so that our heuristics work. */ | |
| 181 | - _Py_atomic_store_relaxed(&gil_last_holder, tstate); | ||
| 181 | + _Py_atomic_store_relaxed(&gil_last_holder, (Py_uintptr_t)tstate); | ||
| 182 | 182 | } | |
| 183 | 183 | ||
| 184 | 184 | MUTEX_LOCK(gil_mutex); | |
@@ -240,7 +240,7 @@ static void take_gil(PyThreadState *tstate) | |||
| 240 | 240 | _Py_ANNOTATE_RWLOCK_ACQUIRED(&gil_locked, /*is_write=*/1); | |
| 241 | 241 | ||
| 242 | 242 | if (tstate != (PyThreadState*)_Py_atomic_load_relaxed(&gil_last_holder)) { | |
| 243 | - _Py_atomic_store_relaxed(&gil_last_holder, tstate); | ||
| 243 | + _Py_atomic_store_relaxed(&gil_last_holder, (Py_uintptr_t)tstate); | ||
| 244 | 244 | ++gil_switch_number; | |
| 245 | 245 | } | |
| 246 | 246 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,11 +3,13 @@ | |||
| 3 | 3 | ||
| 4 | 4 | #include "Python.h" | |
| 5 | 5 | ||
| 6 | - #ifndef Py_BUILD_CORE | ||
| 7 | - /* ensure that PyThreadState_GET() is a macro, not an alias to | ||
| 8 | - * PyThreadState_Get() */ | ||
| 9 | - # error "pystate.c must be compiled with Py_BUILD_CORE defined" | ||
| 10 | - #endif | ||
| 6 | + #define GET_TSTATE() \ | ||
| 7 | + ((PyThreadState*)_Py_atomic_load_relaxed(&_PyThreadState_Current)) | ||
| 8 | + #define SET_TSTATE(value) \ | ||
| 9 | + _Py_atomic_store_relaxed(&_PyThreadState_Current, (Py_uintptr_t)(value)) | ||
| 10 | + #define GET_INTERP_STATE() \ | ||
| 11 | + (GET_TSTATE()->interp) | ||
| 12 | + | ||
| 11 | 13 | ||
| 12 | 14 | /* -------------------------------------------------------------------------- | |
| 13 | 15 | CAUTION | |
@@ -54,7 +56,7 @@ static PyInterpreterState *interp_head = NULL; | |||
| 54 | 56 | ||
| 55 | 57 | /* Assuming the current thread holds the GIL, this is the | |
| 56 | 58 | PyThreadState for the current thread. */ | |
| 57 | - _Py_atomic_address _PyThreadState_Current = {NULL}; | ||
| 59 | + _Py_atomic_address _PyThreadState_Current = {0}; | ||
| 58 | 60 | PyThreadFrameGetter _PyThreadState_GetFrame = NULL; | |
| 59 | 61 | ||
| 60 | 62 | #ifdef WITH_THREAD | |
@@ -260,7 +262,7 @@ PyObject* | |||
| 260 | 262 | PyState_FindModule(struct PyModuleDef* module) | |
| 261 | 263 | { | |
| 262 | 264 | Py_ssize_t index = module->m_base.m_index; | |
| 263 | - PyInterpreterState *state = PyThreadState_GET()->interp; | ||
| 265 | + PyInterpreterState *state = GET_INTERP_STATE(); | ||
| 264 | 266 | PyObject *res; | |
| 265 | 267 | if (module->m_slots) { | |
| 266 | 268 | return NULL; | |
@@ -284,7 +286,7 @@ _PyState_AddModule(PyObject* module, struct PyModuleDef* def) | |||
| 284 | 286 | "PyState_AddModule called on module with slots"); | |
| 285 | 287 | return -1; | |
| 286 | 288 | } | |
| 287 | - state = PyThreadState_GET()->interp; | ||
| 289 | + state = GET_INTERP_STATE(); | ||
| 288 | 290 | if (!def) | |
| 289 | 291 | return -1; | |
| 290 | 292 | if (!state->modules_by_index) { | |
@@ -304,7 +306,7 @@ int | |||
| 304 | 306 | PyState_AddModule(PyObject* module, struct PyModuleDef* def) | |
| 305 | 307 | { | |
| 306 | 308 | Py_ssize_t index; | |
| 307 | - PyInterpreterState *state = PyThreadState_GET()->interp; | ||
| 309 | + PyInterpreterState *state = GET_INTERP_STATE(); | ||
| 308 | 310 | if (!def) { | |
| 309 | 311 | Py_FatalError("PyState_AddModule: Module Definition is NULL"); | |
| 310 | 312 | return -1; | |
@@ -331,7 +333,7 @@ PyState_RemoveModule(struct PyModuleDef* def) | |||
| 331 | 333 | "PyState_RemoveModule called on module with slots"); | |
| 332 | 334 | return -1; | |
| 333 | 335 | } | |
| 334 | - state = PyThreadState_GET()->interp; | ||
| 336 | + state = GET_INTERP_STATE(); | ||
| 335 | 337 | if (index == 0) { | |
| 336 | 338 | Py_FatalError("PyState_RemoveModule: Module index invalid."); | |
| 337 | 339 | return -1; | |
@@ -351,7 +353,7 @@ PyState_RemoveModule(struct PyModuleDef* def) | |||
| 351 | 353 | void | |
| 352 | 354 | _PyState_ClearModules(void) | |
| 353 | 355 | { | |
| 354 | - PyInterpreterState *state = PyThreadState_GET()->interp; | ||
| 356 | + PyInterpreterState *state = GET_INTERP_STATE(); | ||
| 355 | 357 | if (state->modules_by_index) { | |
| 356 | 358 | Py_ssize_t i; | |
| 357 | 359 | for (i = 0; i < PyList_GET_SIZE(state->modules_by_index); i++) { | |
@@ -429,7 +431,7 @@ tstate_delete_common(PyThreadState *tstate) | |||
| 429 | 431 | void | |
| 430 | 432 | PyThreadState_Delete(PyThreadState *tstate) | |
| 431 | 433 | { | |
| 432 | - if (tstate == PyThreadState_GET()) | ||
| 434 | + if (tstate == GET_TSTATE()) | ||
| 433 | 435 | Py_FatalError("PyThreadState_Delete: tstate is still current"); | |
| 434 | 436 | #ifdef WITH_THREAD | |
| 435 | 437 | if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) | |
@@ -443,11 +445,11 @@ PyThreadState_Delete(PyThreadState *tstate) | |||
| 443 | 445 | void | |
| 444 | 446 | PyThreadState_DeleteCurrent() | |
| 445 | 447 | { | |
| 446 | - PyThreadState *tstate = PyThreadState_GET(); | ||
| 448 | + PyThreadState *tstate = GET_TSTATE(); | ||
| 447 | 449 | if (tstate == NULL) | |
| 448 | 450 | Py_FatalError( | |
| 449 | 451 | "PyThreadState_DeleteCurrent: no current tstate"); | |
| 450 | - _Py_atomic_store_relaxed(&_PyThreadState_Current, NULL); | ||
| 452 | + SET_TSTATE(NULL); | ||
| 451 | 453 | if (autoInterpreterState && PyThread_get_key_value(autoTLSkey) == tstate) | |
| 452 | 454 | PyThread_delete_key_value(autoTLSkey); | |
| 453 | 455 | tstate_delete_common(tstate); | |
@@ -496,14 +498,14 @@ _PyThreadState_DeleteExcept(PyThreadState *tstate) | |||
| 496 | 498 | PyThreadState * | |
| 497 | 499 | _PyThreadState_UncheckedGet(void) | |
| 498 | 500 | { | |
| 499 | - return PyThreadState_GET(); | ||
| 501 | + return GET_TSTATE(); | ||
| 500 | 502 | } | |
| 501 | 503 | ||
| 502 | 504 | ||
| 503 | 505 | PyThreadState * | |
| 504 | 506 | PyThreadState_Get(void) | |
| 505 | 507 | { | |
| 506 | - PyThreadState *tstate = PyThreadState_GET(); | ||
| 508 | + PyThreadState *tstate = GET_TSTATE(); | ||
| 507 | 509 | if (tstate == NULL) | |
| 508 | 510 | Py_FatalError("PyThreadState_Get: no current thread"); | |
| 509 | 511 | ||
@@ -514,9 +516,9 @@ PyThreadState_Get(void) | |||
| 514 | 516 | PyThreadState * | |
| 515 | 517 | PyThreadState_Swap(PyThreadState *newts) | |
| 516 | 518 | { | |
| 517 | - PyThreadState *oldts = PyThreadState_GET(); | ||
| 519 | + PyThreadState *oldts = GET_TSTATE(); | ||
| 518 | 520 | ||
| 519 | - _Py_atomic_store_relaxed(&_PyThreadState_Current, newts); | ||
| 521 | + SET_TSTATE(newts); | ||
| 520 | 522 | /* It should not be possible for more than one thread state | |
| 521 | 523 | to be used for a thread. Check this the best we can in debug | |
| 522 | 524 | builds. | |
@@ -545,7 +547,7 @@ PyThreadState_Swap(PyThreadState *newts) | |||
| 545 | 547 | PyObject * | |
| 546 | 548 | PyThreadState_GetDict(void) | |
| 547 | 549 | { | |
| 548 | - PyThreadState *tstate = PyThreadState_GET(); | ||
| 550 | + PyThreadState *tstate = GET_TSTATE(); | ||
| 549 | 551 | if (tstate == NULL) | |
| 550 | 552 | return NULL; | |
| 551 | 553 | ||
@@ -569,8 +571,7 @@ PyThreadState_GetDict(void) | |||
| 569 | 571 | ||
| 570 | 572 | int | |
| 571 | 573 | PyThreadState_SetAsyncExc(long id, PyObject *exc) { | |
| 572 | - PyThreadState *tstate = PyThreadState_GET(); | ||
| 573 | - PyInterpreterState *interp = tstate->interp; | ||
| 574 | + PyInterpreterState *interp = GET_INTERP_STATE(); | ||
| 574 | 575 | PyThreadState *p; | |
| 575 | 576 | ||
| 576 | 577 | /* Although the GIL is held, a few C API functions can be called | |
@@ -691,7 +692,7 @@ PyThreadState_IsCurrent(PyThreadState *tstate) | |||
| 691 | 692 | { | |
| 692 | 693 | /* Must be the tstate for this thread */ | |
| 693 | 694 | assert(PyGILState_GetThisThreadState()==tstate); | |
| 694 | - return tstate == PyThreadState_GET(); | ||
| 695 | + return tstate == GET_TSTATE(); | ||
| 695 | 696 | } | |
| 696 | 697 | ||
| 697 | 698 | /* Internal initialization/finalization functions called by | |
@@ -783,7 +784,7 @@ PyGILState_GetThisThreadState(void) | |||
| 783 | 784 | int | |
| 784 | 785 | PyGILState_Check(void) | |
| 785 | 786 | { | |
| 786 | - PyThreadState *tstate = PyThreadState_GET(); | ||
| 787 | + PyThreadState *tstate = GET_TSTATE(); | ||
| 787 | 788 | return tstate && (tstate == PyGILState_GetThisThreadState()); | |
| 788 | 789 | } | |
| 789 | 790 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments