mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-01 14:45:29 +00:00
Bug 814233 - Make things build when threadsafe/nspr are not present. r=bhackett
This commit is contained in:
parent
e7a51e7a1c
commit
9cbb6cd0f8
@ -9,11 +9,16 @@
|
||||
#include "monitor.h"
|
||||
#include "jscntxt.h"
|
||||
#include "jscompartment.h"
|
||||
#include "prthread.h"
|
||||
#include "forkjoininlines.h"
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
# include "prthread.h"
|
||||
#endif
|
||||
|
||||
namespace js {
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
|
||||
class ForkJoinShared
|
||||
: public TaskExecutor,
|
||||
public Monitor
|
||||
@ -150,31 +155,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
bool
|
||||
ForkJoinSlice::Initialize()
|
||||
{
|
||||
PRStatus status = PR_NewThreadPrivateIndex(&ThreadPrivateIndex, NULL);
|
||||
return status == PR_SUCCESS;
|
||||
}
|
||||
|
||||
ParallelResult ExecuteForkJoinOp(JSContext *cx, ForkJoinOp &op)
|
||||
{
|
||||
# ifndef JS_THREADSAFE_ION
|
||||
return TP_RETRY_SEQUENTIALLY;
|
||||
# else
|
||||
JS_ASSERT(!InParallelSection()); // Recursive use of the ThreadPool is not supported.
|
||||
|
||||
ThreadPool *threadPool = &cx->runtime->threadPool;
|
||||
size_t numThreads = threadPool->numWorkers() + 1; // parallel workers plus this main thread
|
||||
|
||||
ForkJoinShared shared(cx, threadPool, op, numThreads, numThreads - 1);
|
||||
if (!shared.init())
|
||||
return TP_RETRY_SEQUENTIALLY;
|
||||
|
||||
return shared.execute();
|
||||
# endif
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* ForkJoinShared
|
||||
*/
|
||||
@ -453,6 +433,8 @@ ForkJoinShared::endRendezvous(ForkJoinSlice &slice) {
|
||||
PR_NotifyAllCondVar(rendezvousEnd_);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* ForkJoinSlice
|
||||
*/
|
||||
@ -472,25 +454,72 @@ ForkJoinSlice::ForkJoinSlice(PerThreadData *perThreadData,
|
||||
bool
|
||||
ForkJoinSlice::isMainThread()
|
||||
{
|
||||
#ifdef JS_THREADSAFE
|
||||
return perThreadData == &shared->runtime()->mainThread;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
JSRuntime *
|
||||
ForkJoinSlice::runtime()
|
||||
{
|
||||
#ifdef JS_THREADSAFE
|
||||
return shared->runtime();
|
||||
#else
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
ForkJoinSlice::check()
|
||||
{
|
||||
#ifdef JS_THREADSAFE
|
||||
return shared->check(*this);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
ForkJoinSlice::setFatal()
|
||||
{
|
||||
#ifdef JS_THREADSAFE
|
||||
return shared->setFatal();
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
ForkJoinSlice::Initialize()
|
||||
{
|
||||
#ifdef JS_THREADSAFE
|
||||
PRStatus status = PR_NewThreadPrivateIndex(&ThreadPrivateIndex, NULL);
|
||||
return status == PR_SUCCESS;
|
||||
#else
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
|
||||
ParallelResult ExecuteForkJoinOp(JSContext *cx, ForkJoinOp &op)
|
||||
{
|
||||
# ifndef JS_THREADSAFE_ION
|
||||
return TP_RETRY_SEQUENTIALLY;
|
||||
# else
|
||||
JS_ASSERT(!InParallelSection()); // Recursive use of the ThreadPool is not supported.
|
||||
|
||||
ThreadPool *threadPool = &cx->runtime->threadPool;
|
||||
size_t numThreads = threadPool->numWorkers() + 1; // parallel workers plus this main thread
|
||||
|
||||
ForkJoinShared shared(cx, threadPool, op, numThreads, numThreads - 1);
|
||||
if (!shared.init())
|
||||
return TP_RETRY_SEQUENTIALLY;
|
||||
|
||||
return shared.execute();
|
||||
# endif
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -162,7 +162,9 @@ private:
|
||||
friend class AutoRendezvous;
|
||||
friend class AutoSetForkJoinSlice;
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
static PRUintn ThreadPrivateIndex; // initialized by Initialize()
|
||||
#endif
|
||||
|
||||
ForkJoinShared *const shared;
|
||||
};
|
||||
@ -196,7 +198,7 @@ public:
|
||||
/* True if this thread is currently executing a ParallelArray
|
||||
operation across multiple threads. */
|
||||
static inline bool InParallelSection() {
|
||||
# ifdef JS_THREADSAFE_ION
|
||||
# ifdef JS_THREADSAFE
|
||||
return ForkJoinSlice::current() != NULL;
|
||||
# else
|
||||
return false;
|
||||
|
@ -9,13 +9,16 @@ Monitor::Monitor()
|
||||
|
||||
Monitor::~Monitor()
|
||||
{
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_DestroyLock(lock_);
|
||||
PR_DestroyCondVar(condVar_);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool
|
||||
Monitor::init()
|
||||
{
|
||||
#ifdef JS_THREADSAFE
|
||||
lock_ = PR_NewLock();
|
||||
if (!lock_)
|
||||
return false;
|
||||
@ -23,6 +26,7 @@ Monitor::init()
|
||||
condVar_ = PR_NewCondVar(lock_);
|
||||
if (!condVar_)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -11,8 +11,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "mozilla/Util.h"
|
||||
#include "js/Utility.h"
|
||||
#include "prlock.h"
|
||||
#include "prcvar.h"
|
||||
#include "jslock.h"
|
||||
|
||||
namespace js {
|
||||
|
||||
@ -45,25 +44,35 @@ private:
|
||||
|
||||
public:
|
||||
AutoLockMonitor(Monitor &monitor) : monitor(monitor) {
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_Lock(monitor.lock_);
|
||||
#endif
|
||||
}
|
||||
|
||||
~AutoLockMonitor() {
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_Unlock(monitor.lock_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void wait() {
|
||||
#ifdef JS_THREADSAFE
|
||||
mozilla::DebugOnly<PRStatus> status =
|
||||
PR_WaitCondVar(monitor.condVar_, PR_INTERVAL_NO_TIMEOUT);
|
||||
JS_ASSERT(status == PR_SUCCESS);
|
||||
#endif
|
||||
}
|
||||
|
||||
void notify() {
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_NotifyCondVar(monitor.condVar_);
|
||||
#endif
|
||||
}
|
||||
|
||||
void notifyAll() {
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_NotifyAllCondVar(monitor.condVar_);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
@ -73,8 +82,16 @@ class AutoUnlockMonitor
|
||||
Monitor &monitor;
|
||||
|
||||
public:
|
||||
AutoUnlockMonitor(Monitor &monitor) : monitor(monitor) { PR_Unlock(monitor.lock_); }
|
||||
~AutoUnlockMonitor() { PR_Lock(monitor.lock_); }
|
||||
AutoUnlockMonitor(Monitor &monitor) : monitor(monitor) {
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_Unlock(monitor.lock_);
|
||||
#endif
|
||||
}
|
||||
~AutoUnlockMonitor() {
|
||||
#ifdef JS_THREADSAFE
|
||||
PR_Lock(monitor.lock_);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -7,9 +7,12 @@
|
||||
#include "jscntxt.h"
|
||||
#include "jslock.h"
|
||||
#include "vm/threadpool.h"
|
||||
#include "prthread.h"
|
||||
#include "monitor.h"
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
# include "prthread.h"
|
||||
#endif
|
||||
|
||||
namespace js {
|
||||
|
||||
/****************************************************************************
|
||||
@ -81,6 +84,9 @@ ThreadPoolWorker::init()
|
||||
bool
|
||||
ThreadPoolWorker::start()
|
||||
{
|
||||
#ifndef JS_THREADSAFE
|
||||
return false;
|
||||
#else
|
||||
JS_ASSERT(state_ == CREATED);
|
||||
|
||||
// Set state to active now, *before* the thread starts:
|
||||
@ -98,6 +104,7 @@ ThreadPoolWorker::start()
|
||||
}
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@ -197,7 +204,7 @@ ThreadPool::~ThreadPool() {
|
||||
bool
|
||||
ThreadPool::init()
|
||||
{
|
||||
#ifdef JS_THREADSAFE_ION
|
||||
#ifdef JS_THREADSAFE
|
||||
// Compute desired number of workers based on env var or # of CPUs.
|
||||
size_t numWorkers = 0;
|
||||
char *pathreads = getenv("PATHREADS");
|
||||
|
@ -8,17 +8,16 @@
|
||||
#ifndef jsthreadpool_h___
|
||||
#define jsthreadpool_h___
|
||||
|
||||
#if defined(JS_THREADSAFE) && defined(JS_ION)
|
||||
# define JS_THREADSAFE_ION
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include "mozilla/StandardInteger.h"
|
||||
#include "prtypes.h"
|
||||
#include "js/Vector.h"
|
||||
#include "jsalloc.h"
|
||||
#include "prlock.h"
|
||||
#include "prcvar.h"
|
||||
|
||||
#ifdef JS_THREADSAFE
|
||||
# include "prtypes.h"
|
||||
# include "prlock.h"
|
||||
# include "prcvar.h"
|
||||
#endif
|
||||
|
||||
struct JSContext;
|
||||
struct JSRuntime;
|
||||
|
Loading…
Reference in New Issue
Block a user