MINOR: thread: add is_thread_harmless() to know if a thread already is harmless

The harmless status is not re-entrant, so sometimes for signal handling
it can be useful to know if we're already harmless or not. Let's add a
function doing that, and make the debugger use it instead of manipulating
the harmless mask.
This commit is contained in:
Willy Tarreau 2022-07-01 17:11:03 +02:00
parent 598cf3f22e
commit a2b8ed4b44
2 changed files with 14 additions and 1 deletions

View File

@ -116,6 +116,11 @@ static inline void thread_harmless_now()
{ {
} }
static inline int is_thread_harmless()
{
return 1;
}
static inline void thread_harmless_end() static inline void thread_harmless_end()
{ {
} }
@ -251,6 +256,12 @@ static inline void thread_harmless_now()
HA_ATOMIC_OR(&tg_ctx->threads_harmless, ti->ltid_bit); HA_ATOMIC_OR(&tg_ctx->threads_harmless, ti->ltid_bit);
} }
/* Returns non-zero if the current thread is already harmless */
static inline int is_thread_harmless()
{
return !!(HA_ATOMIC_LOAD(&tg_ctx->threads_harmless) & ti->ltid_bit);
}
/* Ends the harmless period started by thread_harmless_now(). Usually this is /* Ends the harmless period started by thread_harmless_now(). Usually this is
* placed after the poll() call. If it is discovered that a job was running and * placed after the poll() call. If it is discovered that a job was running and
* is relying on the thread still being harmless, the thread waits for the * is relying on the thread still being harmless, the thread waits for the

View File

@ -1323,6 +1323,8 @@ void ha_thread_dump_all_to_trash()
/* handles DEBUGSIG to dump the state of the thread it's working on */ /* handles DEBUGSIG to dump the state of the thread it's working on */
void debug_handler(int sig, siginfo_t *si, void *arg) void debug_handler(int sig, siginfo_t *si, void *arg)
{ {
int harmless = is_thread_harmless();
/* first, let's check it's really for us and that we didn't just get /* first, let's check it's really for us and that we didn't just get
* a spurious DEBUGSIG. * a spurious DEBUGSIG.
*/ */
@ -1366,7 +1368,7 @@ void debug_handler(int sig, siginfo_t *si, void *arg)
/* mark the current thread as stuck to detect it upon next invocation /* mark the current thread as stuck to detect it upon next invocation
* if it didn't move. * if it didn't move.
*/ */
if (!(_HA_ATOMIC_LOAD(&tg_ctx->threads_harmless) & ti->ltid_bit) && if (!harmless &&
!(_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_SLEEPING)) !(_HA_ATOMIC_LOAD(&th_ctx->flags) & TH_FL_SLEEPING))
_HA_ATOMIC_OR(&th_ctx->flags, TH_FL_STUCK); _HA_ATOMIC_OR(&th_ctx->flags, TH_FL_STUCK);
} }