mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 10:00:54 +00:00
Snarf'd gtk's NS_GetCurrentThread() implementation.
This commit is contained in:
parent
d9e1a8bf25
commit
b7c77de2ab
@ -29,6 +29,12 @@
|
||||
#include "nsSwitchToUIThread.h"
|
||||
#include "plevent.h"
|
||||
|
||||
//
|
||||
// Static thread local storage index of the Toolkit
|
||||
// object associated with a given thread...
|
||||
//
|
||||
static PRUintn gToolkitTLSIndex = 0;
|
||||
|
||||
//NS_IMPL_ISUPPORTS(nsToolkit, NS_ITOOLKIT_IID)
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
@ -152,6 +158,7 @@ nsToolkit::nsToolkit()
|
||||
nsToolkit::~nsToolkit()
|
||||
{
|
||||
Kill();
|
||||
PR_SetThreadPrivate(gToolkitTLSIndex, nsnull);
|
||||
}
|
||||
|
||||
void nsToolkit::Kill()
|
||||
@ -268,3 +275,52 @@ void nsToolkit::CallMethodAsync(MethodInfo *info)
|
||||
id.sync = false;
|
||||
write_port_etc(eventport, WM_CALLMETHOD, &id, sizeof(id), B_TIMEOUT, 0);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
//
|
||||
// Return the nsIToolkit for the current thread. If a toolkit does not
|
||||
// yet exist, then one will be created...
|
||||
//
|
||||
//-------------------------------------------------------------------------
|
||||
NS_METHOD NS_GetCurrentToolkit(nsIToolkit* *aResult)
|
||||
{
|
||||
nsIToolkit* toolkit = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
PRStatus status;
|
||||
|
||||
// Create the TLS index the first time through...
|
||||
if (0 == gToolkitTLSIndex) {
|
||||
status = PR_NewThreadPrivateIndex(&gToolkitTLSIndex, NULL);
|
||||
if (PR_FAILURE == status) {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
toolkit = (nsIToolkit*)PR_GetThreadPrivate(gToolkitTLSIndex);
|
||||
|
||||
//
|
||||
// Create a new toolkit for this thread...
|
||||
//
|
||||
if (!toolkit) {
|
||||
toolkit = new nsToolkit();
|
||||
|
||||
if (!toolkit) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
NS_ADDREF(toolkit);
|
||||
toolkit->Init(PR_GetCurrentThread());
|
||||
//
|
||||
// The reference stored in the TLS is weak. It is removed in the
|
||||
// nsToolkit destructor...
|
||||
//
|
||||
PR_SetThreadPrivate(gToolkitTLSIndex, (void*)toolkit);
|
||||
}
|
||||
} else {
|
||||
NS_ADDREF(toolkit);
|
||||
}
|
||||
*aResult = toolkit;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user