| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent ed4f3bc commit ef498e0
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -161,8 +161,9 @@ extern void _PyThreadState_Suspend(PyThreadState *tstate); | |||
| 161 | 161 | // Returns 1 on success, 0 if the thread was not in the "detached" state. | |
| 162 | 162 | extern int _PyThreadState_TrySuspendDetached(PyThreadState *tstate); | |
| 163 | 163 | ||
| 164 | - // Undo a successful _PyThreadState_TrySuspendDetached(): switch the thread | ||
| 165 | - // back to "detached" and wake it if it is waiting to attach. | ||
| 164 | + // Resume a thread suspended by _PyThreadState_TrySuspendDetached() or a | ||
| 165 | + // stop-the-world pause: switch it back to "detached" or "detached-waiting" | ||
| 166 | + // and wake it if it is waiting to attach. | ||
| 166 | 167 | extern void _PyThreadState_ResumeDetached(PyThreadState *tstate); | |
| 167 | 168 | #endif | |
| 168 | 169 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2401,10 +2401,24 @@ void | |||
| 2401 | 2401 | _PyThreadState_ResumeDetached(PyThreadState *tstate) | |
| 2402 | 2402 | { | |
| 2403 | 2403 | assert(tstate != _PyThreadState_GET()); | |
| 2404 | - assert(_Py_atomic_load_int_relaxed(&tstate->state) == _Py_THREAD_SUSPENDED); | ||
| 2405 | - _Py_atomic_store_int(&tstate->state, _Py_THREAD_DETACHED); | ||
| 2404 | + int state = _Py_atomic_load_int_relaxed(&tstate->state); | ||
| 2405 | + int next_state; | ||
| 2406 | + do { | ||
| 2407 | + assert(state == _Py_THREAD_SUSPENDED || | ||
| 2408 | + state == _Py_THREAD_SUSPENDED_WAITING); | ||
| 2409 | + if (state == _Py_THREAD_SUSPENDED_WAITING) { | ||
| 2410 | + next_state = _Py_THREAD_DETACHED_WAITING; | ||
| 2411 | + } | ||
| 2412 | + else { | ||
| 2413 | + next_state = _Py_THREAD_DETACHED; | ||
| 2414 | + } | ||
| 2415 | + // Retry if an attach waiter registered concurrently. | ||
| 2416 | + } while (!_Py_atomic_compare_exchange_int( | ||
| 2417 | + &tstate->state, &state, next_state)); | ||
| 2406 | 2418 | // Wake the thread if it is parked in tstate_wait_attach(). | |
| 2407 | - _PyParkingLot_UnparkAll(&tstate->state); | ||
| 2419 | + if (state == _Py_THREAD_SUSPENDED_WAITING) { | ||
| 2420 | + _PyParkingLot_UnparkAll(&tstate->state); | ||
| 2421 | + } | ||
| 2408 | 2422 | } | |
| 2409 | 2423 | #endif | |
| 2410 | 2424 | ||
@@ -2526,30 +2540,6 @@ stop_the_world(struct _stoptheworld_state *stw) | |||
| 2526 | 2540 | stw->world_stopped = 1; | |
| 2527 | 2541 | } | |
| 2528 | 2542 | ||
| 2529 | - static void | ||
| 2530 | - tstate_resume(PyThreadState *tstate) | ||
| 2531 | - { | ||
| 2532 | - assert(tstate != _PyThreadState_GET()); | ||
| 2533 | - int state = _Py_atomic_load_int_relaxed(&tstate->state); | ||
| 2534 | - int next_state; | ||
| 2535 | - do { | ||
| 2536 | - assert(state == _Py_THREAD_SUSPENDED || | ||
| 2537 | - state == _Py_THREAD_SUSPENDED_WAITING); | ||
| 2538 | - if (state == _Py_THREAD_SUSPENDED_WAITING) { | ||
| 2539 | - next_state = _Py_THREAD_DETACHED_WAITING; | ||
| 2540 | - } | ||
| 2541 | - else { | ||
| 2542 | - next_state = _Py_THREAD_DETACHED; | ||
| 2543 | - } | ||
| 2544 | - // Retry if an attach waiter registered concurrently. | ||
| 2545 | - } while (!_Py_atomic_compare_exchange_int( | ||
| 2546 | - &tstate->state, &state, next_state)); | ||
| 2547 | - // Wake the thread if it is parked in tstate_wait_attach(). | ||
| 2548 | - if (state == _Py_THREAD_SUSPENDED_WAITING) { | ||
| 2549 | - _PyParkingLot_UnparkAll(&tstate->state); | ||
| 2550 | - } | ||
| 2551 | - } | ||
| 2552 | - | ||
| 2553 | 2543 | static void | |
| 2554 | 2544 | start_the_world(struct _stoptheworld_state *stw) | |
| 2555 | 2545 | { | |
@@ -2563,7 +2553,7 @@ start_the_world(struct _stoptheworld_state *stw) | |||
| 2563 | 2553 | _Py_FOR_EACH_STW_INTERP(stw, i) { | |
| 2564 | 2554 | _Py_FOR_EACH_TSTATE_UNLOCKED(i, t) { | |
| 2565 | 2555 | if (t != stw->requester) { | |
| 2566 | - tstate_resume(t); | ||
| 2556 | + _PyThreadState_ResumeDetached(t); | ||
| 2567 | 2557 | } | |
| 2568 | 2558 | } | |
| 2569 | 2559 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments