gecko/xpcom/threads/nsThread.h
Ehsan Akhgari 0fd9123eac Bug 579517 - Part 1: Automated conversion of NSPR numeric types to stdint types in Gecko; r=bsmedberg
This patch was generated by a script.  Here's the source of the script for
future reference:

function convert() {
echo "Converting $1 to $2..."
find . ! -wholename "*nsprpub*" \
       ! -wholename "*security/nss*" \
       ! -wholename "*/.hg*" \
       ! -wholename "obj-ff-dbg*" \
       ! -name nsXPCOMCID.h \
       ! -name prtypes.h \
         -type f \
      \( -iname "*.cpp" \
         -o -iname "*.h" \
         -o -iname "*.c" \
         -o -iname "*.cc" \
         -o -iname "*.idl" \
         -o -iname "*.ipdl" \
         -o -iname "*.ipdlh" \
         -o -iname "*.mm" \) | \
    xargs -n 1 sed -i -e "s/\b$1\b/$2/g"
}

convert PRInt8 int8_t
convert PRUint8 uint8_t
convert PRInt16 int16_t
convert PRUint16 uint16_t
convert PRInt32 int32_t
convert PRUint32 uint32_t
convert PRInt64 int64_t
convert PRUint64 uint64_t

convert PRIntn int
convert PRUintn unsigned

convert PRSize size_t

convert PROffset32 int32_t
convert PROffset64 int64_t

convert PRPtrdiff ptrdiff_t

convert PRFloat64 double
2012-08-22 11:56:38 -04:00

139 lines
3.6 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef nsThread_h__
#define nsThread_h__
#include "mozilla/Mutex.h"
#include "nsIThreadInternal.h"
#include "nsISupportsPriority.h"
#include "nsEventQueue.h"
#include "nsThreadUtils.h"
#include "nsString.h"
#include "nsTObserverArray.h"
#include "mozilla/Attributes.h"
// A native thread
class nsThread MOZ_FINAL : public nsIThreadInternal,
public nsISupportsPriority
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIEVENTTARGET
NS_DECL_NSITHREAD
NS_DECL_NSITHREADINTERNAL
NS_DECL_NSISUPPORTSPRIORITY
enum MainThreadFlag {
MAIN_THREAD,
NOT_MAIN_THREAD
};
nsThread(MainThreadFlag aMainThread, uint32_t aStackSize);
// Initialize this as a wrapper for a new PRThread.
nsresult Init();
// Initialize this as a wrapper for the current PRThread.
nsresult InitCurrentThread();
// The PRThread corresponding to this thread.
PRThread *GetPRThread() { return mThread; }
// If this flag is true, then the nsThread was created using
// nsIThreadManager::NewThread.
bool ShutdownRequired() { return mShutdownRequired; }
// Clear the observer list.
void ClearObservers() { mEventObservers.Clear(); }
private:
friend class nsThreadShutdownEvent;
~nsThread();
bool ShuttingDown() { return mShutdownContext != nullptr; }
static void ThreadFunc(void *arg);
// Helper
already_AddRefed<nsIThreadObserver> GetObserver() {
nsIThreadObserver *obs;
nsThread::GetObserver(&obs);
return already_AddRefed<nsIThreadObserver>(obs);
}
// Wrappers for event queue methods:
bool GetEvent(bool mayWait, nsIRunnable **event) {
return mEvents.GetEvent(mayWait, event);
}
nsresult PutEvent(nsIRunnable *event);
// This lock protects access to mObserver, mEvents and mEventsAreDoomed.
// All of those fields are only modified on the thread itself (never from
// another thread). This means that we can avoid holding the lock while
// using mObserver and mEvents on the thread itself. When calling PutEvent
// on mEvents, we have to hold the lock to synchronize with PopEventQueue.
mozilla::Mutex mLock;
nsCOMPtr<nsIThreadObserver> mObserver;
// Only accessed on the target thread.
nsAutoTObserverArray<nsCOMPtr<nsIThreadObserver>, 2> mEventObservers;
nsEventQueue mEvents;
int32_t mPriority;
PRThread *mThread;
uint32_t mRunningEvent; // counter
uint32_t mStackSize;
struct nsThreadShutdownContext *mShutdownContext;
bool mShutdownRequired;
// Set to true when events posted to this thread will never run.
bool mEventsAreDoomed;
MainThreadFlag mIsMainThread;
};
//-----------------------------------------------------------------------------
class nsThreadSyncDispatch : public nsRunnable {
public:
nsThreadSyncDispatch(nsIThread *origin, nsIRunnable *task)
: mOrigin(origin), mSyncTask(task), mResult(NS_ERROR_NOT_INITIALIZED) {
}
bool IsPending() {
return mSyncTask != nullptr;
}
nsresult Result() {
return mResult;
}
private:
NS_DECL_NSIRUNNABLE
nsCOMPtr<nsIThread> mOrigin;
nsCOMPtr<nsIRunnable> mSyncTask;
nsresult mResult;
};
namespace mozilla {
/**
* This function causes the main thread to fire a memory pressure event at its
* next available opportunity.
*
* You may call this function from any thread.
*/
void ScheduleMemoryPressureEvent();
} // namespace mozilla
#endif // nsThread_h__