Classes | Defines | Functions

nsThreadUtils.h File Reference

#include "prthread.h"
#include "prinrval.h"
#include "nsIThreadManager.h"
#include "nsIThread.h"
#include "nsIRunnable.h"
#include "nsStringGlue.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "mozilla/threads/nsThreadIDs.h"
Include dependency graph for nsThreadUtils.h:
This graph shows which files directly or indirectly include this file:

Classes

class  nsRunnable
class  nsRunnableMethod< ClassType, ReturnType, Owning >
class  nsRunnableMethod< ClassType, ReturnType, Owning >::ReturnTypeEnforcer< OtherReturnType >
class  nsRunnableMethod< ClassType, ReturnType, Owning >::ReturnTypeEnforcer< already_AddRefed< T > >
struct  nsRunnableMethodReceiver< ClassType, Owning >
struct  nsRunnableMethodReceiver< ClassType, false >
struct  nsRunnableMethodTraits< R(C::*)(), Owning >
class  nsRunnableMethodImpl< Method, Owning >
class  nsRevocableEventPtr< T >

Defines

#define IMETHOD_VISIBILITY   NS_COM_GLUE
#define IMETHOD_VISIBILITY   NS_VISIBILITY_HIDDEN

Functions

nsresult NS_NewThread (nsIThread **result, nsIRunnable *initialEvent=0L)
 Create a new thread, and optionally provide an initial event for the thread.
nsresult NS_GetCurrentThread (nsIThread **result)
 Get a reference to the current thread.
nsresult NS_GetMainThread (nsIThread **result)
 Get a reference to the main thread.
bool NS_IsMainThread ()
 Test to see if the current thread is the main thread.
nsresult NS_DispatchToCurrentThread (nsIRunnable *event)
 Dispatch the given event to the current thread.
nsresult NS_DispatchToMainThread (nsIRunnable *event, PRUint32 dispatchFlags=NS_DISPATCH_NORMAL)
 Dispatch the given event to the main thread.
nsresult NS_ProcessPendingEvents (nsIThread *thread, PRIntervalTime timeout=0xffffffffUL)
 Process all pending events for the given thread before returning.
PRBool NS_HasPendingEvents (nsIThread *thread=0L)
 Shortcut for nsIThread::HasPendingEvents.
PRBool NS_ProcessNextEvent (nsIThread *thread=0L, PRBool mayWait=1)
 Shortcut for nsIThread::ProcessNextEvent.
already_AddRefed< nsIThreaddo_GetCurrentThread ()
already_AddRefed< nsIThreaddo_GetMainThread ()
template<typename PtrType , typename Method >
nsRunnableMethodTraits< Method,
true >::base_type * 
NS_NewRunnableMethod (PtrType ptr, Method method)
template<typename PtrType , typename Method >
nsRunnableMethodTraits< Method,
false >::base_type * 
NS_NewNonOwningRunnableMethod (PtrType ptr, Method method)

Define Documentation

#define IMETHOD_VISIBILITY   NS_COM_GLUE
#define IMETHOD_VISIBILITY   NS_VISIBILITY_HIDDEN

Function Documentation

already_AddRefed<nsIThread> do_GetCurrentThread (  )  [inline]
already_AddRefed<nsIThread> do_GetMainThread (  )  [inline]
nsresult NS_DispatchToCurrentThread ( nsIRunnable event  ) 

Dispatch the given event to the current thread.

Parameters:
event The event to dispatch.
Returns:
NS_ERROR_INVALID_ARG If event is null.
nsresult NS_DispatchToMainThread ( nsIRunnable event,
PRUint32  dispatchFlags = NS_DISPATCH_NORMAL 
)

Dispatch the given event to the main thread.

Parameters:
event The event to dispatch.
dispatchFlags The flags to pass to the main thread's dispatch method.
Returns:
NS_ERROR_INVALID_ARG If event is null.
nsresult NS_GetCurrentThread ( nsIThread **  result  ) 

Get a reference to the current thread.

Parameters:
result The resulting nsIThread object.
nsresult NS_GetMainThread ( nsIThread **  result  ) 

Get a reference to the main thread.

Parameters:
result The resulting nsIThread object.
PRBool NS_HasPendingEvents ( nsIThread thread = 0L  ) 

Shortcut for nsIThread::HasPendingEvents.

It is an error to call this function when the given thread is not the current thread. This function will return PR_FALSE if called from some other thread.

Parameters:
thread The current thread or null.
Returns:
A boolean value that if "true" indicates that there are pending events in the current thread's event queue.
bool NS_IsMainThread (  ) 

Test to see if the current thread is the main thread.

Returns:
PR_TRUE if the current thread is the main thread, and PR_FALSE otherwise.
template<typename PtrType , typename Method >
nsRunnableMethodTraits<Method, false>::base_type* NS_NewNonOwningRunnableMethod ( PtrType  ptr,
Method  method 
)
template<typename PtrType , typename Method >
nsRunnableMethodTraits<Method, true>::base_type* NS_NewRunnableMethod ( PtrType  ptr,
Method  method 
)
nsresult NS_NewThread ( nsIThread **  result,
nsIRunnable initialEvent = 0L 
)

Create a new thread, and optionally provide an initial event for the thread.

Parameters:
result The resulting nsIThread object.
initialEvent The initial event to run on this thread. This parameter may be null.
Returns:
NS_ERROR_INVALID_ARG Indicates that the given name is not unique.
PRBool NS_ProcessNextEvent ( nsIThread thread = 0L,
PRBool  mayWait = 1 
)

Shortcut for nsIThread::ProcessNextEvent.

It is an error to call this function when the given thread is not the current thread. This function will simply return PR_FALSE if called from some other thread.

Parameters:
thread The current thread or null.
mayWait A boolean parameter that if "true" indicates that the method may block the calling thread to wait for a pending event.
Returns:
A boolean value that if "true" indicates that an event from the current thread's event queue was processed.
nsresult NS_ProcessPendingEvents ( nsIThread thread,
PRIntervalTime  timeout = 0xffffffffUL 
)

Process all pending events for the given thread before returning.

This method simply calls ProcessNextEvent on the thread while HasPendingEvents continues to return true and the time spent in NS_ProcessPendingEvents does not exceed the given timeout value.

Parameters:
thread The thread object for which to process pending events. If null, then events will be processed for the current thread.
timeout The maximum number of milliseconds to spend processing pending events. Events are not pre-empted to honor this timeout. Rather, the timeout value is simply used to determine whether or not to process another event. Pass PR_INTERVAL_NO_TIMEOUT to specify no timeout.