diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c index 89f6137b6999..40652b6e85e3 100644 --- a/sys/kern/kern_thread.c +++ b/sys/kern/kern_thread.c @@ -981,7 +981,12 @@ void tidhash_add(struct thread *td) { rw_wlock(&tidhash_lock); - LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash); + thread_lock(td); + if ((td->td_flags & TDF_TIDHASH) == 0) { + LIST_INSERT_HEAD(TIDHASH(td->td_tid), td, td_hash); + td->td_flags |= TDF_TIDHASH; + } + thread_unlock(td); rw_wunlock(&tidhash_lock); } @@ -989,6 +994,11 @@ void tidhash_remove(struct thread *td) { rw_wlock(&tidhash_lock); - LIST_REMOVE(td, td_hash); + thread_lock(td); + if ((td->td_flags & TDF_TIDHASH) != 0) { + LIST_REMOVE(td, td_hash); + td->td_flags &= ~TDF_TIDHASH; + } + thread_unlock(td); rw_wunlock(&tidhash_lock); } diff --git a/sys/sys/proc.h b/sys/sys/proc.h index 9bce5691c20d..21fc29fab94c 100644 --- a/sys/sys/proc.h +++ b/sys/sys/proc.h @@ -353,7 +353,7 @@ do { \ #define TDF_NEEDRESCHED 0x00010000 /* Thread needs to yield. */ #define TDF_NEEDSIGCHK 0x00020000 /* Thread may need signal delivery. */ #define TDF_NOLOAD 0x00040000 /* Ignore during load avg calculations. */ -#define TDF_UNUSED19 0x00080000 /* Thread is sleeping on a umtx. */ +#define TDF_TIDHASH 0x00080000 /* Thread is on hash table. */ #define TDF_THRWAKEUP 0x00100000 /* Libthr thread must not suspend itself. */ #define TDF_UNUSED21 0x00200000 /* --available-- */ #define TDF_SWAPINREQ 0x00400000 /* Swapin request due to wakeup. */