Add a flag TDF_TIDHASH to prevent a thread from being

added to or removed from thread hash table multiple times.
This commit is contained in:
David Xu 2010-10-12 00:36:56 +00:00
parent 5f7f699749
commit 96f231fde9
2 changed files with 13 additions and 3 deletions

View File

@ -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);
}

View File

@ -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. */