Closed Bug 112397 Opened 23 years ago Closed 23 years ago

Add IsMainThread to nsIThread

Categories

(Core :: XPCOM, defect)

x86
Windows 2000
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: dougt, Assigned: dougt)

Details

Attachments

(1 file)

I need a cheap way to check if the current thread is the main thread. I added a method nsIThread::IsMainThread. Check out the diffs.
This snatch of code is somewhat common throughout Mozilla: nsCOMPtr<nsIThread> main; nsCOMPtr<nsIThread> current; nsIThread::GetMainThread(getter_AddRefs(main)); nsIThread::GetCurrent(getter_AddRefs(current)); if (main == current) ... Too much hassle? Nnnh. I guess this new method won't hurt anything. I find its name confusing, though, since the method has nothing to do with any nsIThread object you may be holding onto. How about calling it CurrentThreadIsMainThread, and r=danm.
The problem with the snippet you suggested is: 1) two atomic sets for the addref'ing 2) GetThread() can create a nsIThread for the current thread. This routine just makes things faster. CurrentThreadIsMainThread is a bit wordy. Isn't CurrentThread implied but the function call itself. I don't care either way, i guess. Thanks for the review.
i prefer nsIThread::IsMainThread over nsIThread::CurrentThreadIsMainThread
Comment on attachment 59523 [details] [diff] [review] Adds nsIThread::IsMainThread sr=darin
Attachment #59523 - Flags: superreview+
Checking in nsThread.cpp; /cvsroot/mozilla/xpcom/threads/nsThread.cpp,v <-- nsThread.cpp new revision: 1.40; previous revision: 1.39 done Checking in nsIThread.idl; /cvsroot/mozilla/xpcom/threads/nsIThread.idl,v <-- nsIThread.idl new revision: 1.7; previous revision: 1.6 done Thanks
Status: NEW → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: