From 47085e4f4f287774e5a63903286a623ee9c075a9 Mon Sep 17 00:00:00 2001 From: "warren%netscape.com" Date: Tue, 6 Apr 1999 06:09:15 +0000 Subject: [PATCH] Added GetIThread method --- base/public/nsIThread.h | 4 ++++ base/src/nsThread.cpp | 8 +++++++- xpcom/threads/nsIThread.h | 4 ++++ xpcom/threads/nsThread.cpp | 8 +++++++- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/base/public/nsIThread.h b/base/public/nsIThread.h index bef5bad6b0a..4957301372d 100644 --- a/base/public/nsIThread.h +++ b/base/public/nsIThread.h @@ -59,8 +59,12 @@ class nsIThread : public nsISupports public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITHREAD_IID); + // returns the nsIThread for the current thread: static NS_BASE nsresult GetCurrent(nsIThread* *result); + // returns the nsIThread for an arbitrary PRThread: + static NS_BASE nsresult GetIThread(PRThread* prthread, nsIThread* *result); + NS_IMETHOD Join() = 0; NS_IMETHOD GetPriority(PRThreadPriority *result) = 0; diff --git a/base/src/nsThread.cpp b/base/src/nsThread.cpp index b65545342a8..383eb397919 100644 --- a/base/src/nsThread.cpp +++ b/base/src/nsThread.cpp @@ -201,6 +201,12 @@ nsThread::RegisterThreadSelf() NS_BASE nsresult nsIThread::GetCurrent(nsIThread* *result) +{ + return GetIThread(PR_CurrentThread(), result); +} + +NS_BASE nsresult +nsIThread::GetIThread(PRThread* prthread, nsIThread* *result) { PRStatus status; nsThread* thread; @@ -219,7 +225,7 @@ nsIThread::GetCurrent(nsIThread* *result) if (thread == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(thread); - thread->SetPRThread(PR_CurrentThread()); + thread->SetPRThread(prthread); nsresult rv = thread->RegisterThreadSelf(); if (NS_FAILED(rv)) return rv; } diff --git a/xpcom/threads/nsIThread.h b/xpcom/threads/nsIThread.h index bef5bad6b0a..4957301372d 100644 --- a/xpcom/threads/nsIThread.h +++ b/xpcom/threads/nsIThread.h @@ -59,8 +59,12 @@ class nsIThread : public nsISupports public: NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITHREAD_IID); + // returns the nsIThread for the current thread: static NS_BASE nsresult GetCurrent(nsIThread* *result); + // returns the nsIThread for an arbitrary PRThread: + static NS_BASE nsresult GetIThread(PRThread* prthread, nsIThread* *result); + NS_IMETHOD Join() = 0; NS_IMETHOD GetPriority(PRThreadPriority *result) = 0; diff --git a/xpcom/threads/nsThread.cpp b/xpcom/threads/nsThread.cpp index b65545342a8..383eb397919 100644 --- a/xpcom/threads/nsThread.cpp +++ b/xpcom/threads/nsThread.cpp @@ -201,6 +201,12 @@ nsThread::RegisterThreadSelf() NS_BASE nsresult nsIThread::GetCurrent(nsIThread* *result) +{ + return GetIThread(PR_CurrentThread(), result); +} + +NS_BASE nsresult +nsIThread::GetIThread(PRThread* prthread, nsIThread* *result) { PRStatus status; nsThread* thread; @@ -219,7 +225,7 @@ nsIThread::GetCurrent(nsIThread* *result) if (thread == nsnull) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(thread); - thread->SetPRThread(PR_CurrentThread()); + thread->SetPRThread(prthread); nsresult rv = thread->RegisterThreadSelf(); if (NS_FAILED(rv)) return rv; }