port modules/oji
git-svn-id: svn://10.0.0.236/branches/THREADS_20060213_BRANCH@190840 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -64,7 +64,7 @@ EXPORTS = \
|
||||
nsISymantecDebugger.h \
|
||||
nsISecureEnv.h \
|
||||
ProxyJNI.h \
|
||||
nsIThreadManager.h \
|
||||
nsIJVMThreadManager.h \
|
||||
nsILiveConnectManager.h \
|
||||
$(NULL)
|
||||
|
||||
|
||||
130
mozilla/modules/oji/public/nsIJVMThreadManager.h
Normal file
130
mozilla/modules/oji/public/nsIJVMThreadManager.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim:set ts=4 sw=4 sts=4 ci et: */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the
|
||||
* License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef nsIJVMThreadManager_h___
|
||||
#define nsIJVMThreadManager_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIRunnable.h"
|
||||
#include "nspr.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Thread Manager
|
||||
// This interface provides thread primitives.
|
||||
|
||||
#define NS_IJVMTHREADMANAGER_IID \
|
||||
{ /* 97bb54c0-6846-11d2-801f-00805f71101c */ \
|
||||
0x97bb54c0, \
|
||||
0x6846, \
|
||||
0x11d2, \
|
||||
{0x80, 0x1f, 0x00, 0x80, 0x5f, 0x71, 0x10, 0x1c} \
|
||||
}
|
||||
|
||||
class nsIRunnable;
|
||||
|
||||
class nsIJVMThreadManager : public nsISupports {
|
||||
public:
|
||||
NS_DECLARE_STATIC_IID_ACCESSOR(NS_IJVMTHREADMANAGER_IID)
|
||||
|
||||
/**
|
||||
* Returns a unique identifier for the "current" system thread.
|
||||
*/
|
||||
NS_IMETHOD
|
||||
GetCurrentThread(PRThread* *threadID) = 0;
|
||||
|
||||
/**
|
||||
* Pauses the current thread for the specified number of milliseconds.
|
||||
* If milli is zero, then merely yields the CPU if another thread of
|
||||
* greater or equal priority.
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Sleep(PRUint32 milli = 0) = 0;
|
||||
|
||||
/**
|
||||
* Creates a unique monitor for the specified address, and makes the
|
||||
* current system thread the owner of the monitor.
|
||||
*/
|
||||
NS_IMETHOD
|
||||
EnterMonitor(void* address) = 0;
|
||||
|
||||
/**
|
||||
* Exits the monitor associated with the address.
|
||||
*/
|
||||
NS_IMETHOD
|
||||
ExitMonitor(void* address) = 0;
|
||||
|
||||
/**
|
||||
* Waits on the monitor associated with the address (must be entered already).
|
||||
* If milli is 0, wait indefinitely.
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Wait(void* address, PRUint32 milli = 0) = 0;
|
||||
|
||||
/**
|
||||
* Notifies a single thread waiting on the monitor associated with the address (must be entered already).
|
||||
*/
|
||||
NS_IMETHOD
|
||||
Notify(void* address) = 0;
|
||||
|
||||
/**
|
||||
* Notifies all threads waiting on the monitor associated with the address (must be entered already).
|
||||
*/
|
||||
NS_IMETHOD
|
||||
NotifyAll(void* address) = 0;
|
||||
|
||||
/**
|
||||
* Creates a new thread, calling the specified runnable's Run method (a la Java).
|
||||
*/
|
||||
NS_IMETHOD
|
||||
CreateThread(PRThread **thread, nsIRunnable* runnable) = 0;
|
||||
|
||||
/**
|
||||
* Posts an event to specified thread, calling the runnable from that thread.
|
||||
* @param threadID thread to call runnable from
|
||||
* @param runnable object to invoke from thread
|
||||
* @param async if true, won't block current thread waiting for result
|
||||
*/
|
||||
NS_IMETHOD
|
||||
PostEvent(PRThread* thread, nsIRunnable* runnable, PRBool async) = 0;
|
||||
};
|
||||
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(nsIJVMThreadManager, NS_IJVMTHREADMANAGER_IID)
|
||||
|
||||
#endif /* nsIJVMThreadManager_h___ */
|
||||
@@ -58,7 +58,7 @@
|
||||
#include "nsISymantecDebugManager.h"
|
||||
#include "nsISymantecDebugger.h"
|
||||
#include "nsILiveconnect.h"
|
||||
#include "nsIThreadManager.h"
|
||||
#include "nsIJVMThreadManager.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
#include "jsdbgapi.h"
|
||||
#include "nsError.h"
|
||||
|
||||
#include "nsIThreadManager.h"
|
||||
#include "nsIJVMThreadManager.h"
|
||||
#include "nsISecurityContext.h"
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
||||
/* vim:set ts=4 sw=4 sts=4 ci et: */
|
||||
/*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
@@ -60,7 +61,8 @@
|
||||
#include "ProxyJNI.h"
|
||||
#include "nsIPluginHost.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIThreadManager.h"
|
||||
#include "nsIThread.h"
|
||||
|
||||
// All these interfaces are necessary just to get the damn
|
||||
// nsIWebBrowserChrome to send the "Starting Java" message to the status
|
||||
@@ -104,8 +106,6 @@ static NS_DEFINE_CID(kJVMManagerCID, NS_JVMMANAGER_CID);
|
||||
|
||||
static NS_DEFINE_CID(kPluginManagerCID, NS_PLUGINMANAGER_CID);
|
||||
|
||||
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||
|
||||
// FIXME -- need prototypes for these functions!!! XXX
|
||||
#ifdef XP_MAC
|
||||
extern "C" {
|
||||
@@ -117,7 +117,7 @@ void stopAsyncCursors(void);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIJVMManagerIID, NS_IJVMMANAGER_IID);
|
||||
static NS_DEFINE_IID(kIThreadManagerIID, NS_ITHREADMANAGER_IID);
|
||||
static NS_DEFINE_IID(kIJVMThreadManagerIID, NS_IJVMTHREADMANAGER_IID);
|
||||
static NS_DEFINE_IID(kILiveConnectManagerIID, NS_ILIVECONNECTMANAGER_IID);
|
||||
static NS_DEFINE_IID(kIJVMPluginIID, NS_IJVMPLUGIN_IID);
|
||||
|
||||
@@ -291,57 +291,22 @@ nsJVMManager::CreateThread(PRThread **outThread, nsIRunnable* runnable)
|
||||
return (thread != NULL ? NS_OK : NS_ERROR_FAILURE);
|
||||
}
|
||||
|
||||
struct JVMRunnableEvent : PLEvent {
|
||||
JVMRunnableEvent(nsIRunnable* runnable);
|
||||
~JVMRunnableEvent();
|
||||
|
||||
nsIRunnable* mRunnable;
|
||||
};
|
||||
|
||||
static void PR_CALLBACK
|
||||
handleRunnableEvent(JVMRunnableEvent* aEvent)
|
||||
{
|
||||
aEvent->mRunnable->Run();
|
||||
}
|
||||
|
||||
static void PR_CALLBACK
|
||||
destroyRunnableEvent(JVMRunnableEvent* aEvent)
|
||||
{
|
||||
delete aEvent;
|
||||
}
|
||||
|
||||
JVMRunnableEvent::JVMRunnableEvent(nsIRunnable* runnable)
|
||||
: mRunnable(runnable)
|
||||
{
|
||||
NS_ADDREF(mRunnable);
|
||||
PL_InitEvent(this, nsnull, PLHandleEventProc(handleRunnableEvent), PLDestroyEventProc(&destroyRunnableEvent));
|
||||
}
|
||||
|
||||
JVMRunnableEvent::~JVMRunnableEvent()
|
||||
{
|
||||
NS_RELEASE(mRunnable);
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsJVMManager::PostEvent(PRThread* thread, nsIRunnable* runnable, PRBool async)
|
||||
nsJVMManager::PostEvent(PRThread* prthread, nsIRunnable* runnable, PRBool async)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIEventQueueService> eventService =
|
||||
do_GetService(kEventQueueServiceCID, &rv);
|
||||
nsCOMPtr<nsIThreadManager> mgr =
|
||||
do_GetService(NS_THREADMANAGER_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIEventQueue> eventQueue = NULL;
|
||||
rv = eventService->GetThreadEventQueue(thread, getter_AddRefs(eventQueue));
|
||||
nsCOMPtr<nsIThread> thread;
|
||||
rv = mgr->GetThreadFromPRThread(prthread, getter_AddRefs(thread));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
JVMRunnableEvent* runnableEvent = new JVMRunnableEvent(runnable);
|
||||
if (runnableEvent == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (async)
|
||||
eventQueue->PostEvent(runnableEvent);
|
||||
else
|
||||
eventQueue->PostSynchronousEvent(runnableEvent, nsnull);
|
||||
return rv;
|
||||
NS_ENSURE_STATE(thread);
|
||||
|
||||
return thread->Dispatch(runnable, async ? NS_DISPATCH_NORMAL
|
||||
: NS_DISPATCH_SYNC);
|
||||
}
|
||||
|
||||
nsJVMManager::nsJVMManager(nsISupports* outer)
|
||||
@@ -386,8 +351,8 @@ nsJVMManager::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr)
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIThreadManagerIID)) {
|
||||
*aInstancePtr = (void*) NS_STATIC_CAST(nsIThreadManager*, this);
|
||||
if (aIID.Equals(kIJVMThreadManagerIID)) {
|
||||
*aInstancePtr = (void*) NS_STATIC_CAST(nsIJVMThreadManager*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -62,7 +62,8 @@ class nsIWebBrowserChrome;
|
||||
* nsIJVMManager is the more limited interface what the JVM plugin sees.
|
||||
******************************************************************************/
|
||||
|
||||
struct nsJVMManager : public nsIJVMManager, public nsIThreadManager, public nsILiveConnectManager, public nsIObserver {
|
||||
struct nsJVMManager : public nsIJVMManager, public nsIJVMThreadManager,
|
||||
public nsILiveConnectManager, public nsIObserver {
|
||||
public:
|
||||
|
||||
NS_DECL_AGGREGATED
|
||||
@@ -71,7 +72,7 @@ public:
|
||||
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
/* from nsIThreadManager: */
|
||||
/* from nsIJVMThreadManager: */
|
||||
|
||||
/**
|
||||
* Returns a unique identifier for the "current" system thread.
|
||||
|
||||
Reference in New Issue
Block a user