#ifndef threading_Mutex_h
#define threading_Mutex_h
#include "mozilla/Assertions.h"
#include "mozilla/Move.h"
#include "mozilla/PlatformMutex.h"
#include "mozilla/ThreadLocal.h"
#include "mozilla/Vector.h"
namespace js {
struct MutexId {
const char* name;
uint32_t order;
};
#ifndef DEBUG
class Mutex : public mozilla::detail::MutexImpl {
public:
static bool Init() { return true; }
static void ShutDown() {}
explicit Mutex(const MutexId& id)
: mozilla::detail::MutexImpl(
mozilla::recordreplay::Behavior::DontPreserve) {}
using MutexImpl::lock;
using MutexImpl::unlock;
};
#else
class Mutex : public mozilla::detail::MutexImpl {
public:
static bool Init();
static void ShutDown();
explicit Mutex(const MutexId& id)
: mozilla::detail::MutexImpl(
mozilla::recordreplay::Behavior::DontPreserve),
id_(id) {
MOZ_ASSERT(id_.order != 0);
}
void lock();
void unlock();
bool ownedByCurrentThread() const;
private:
const MutexId id_;
using MutexVector = mozilla::Vector<const Mutex*>;
static MOZ_THREAD_LOCAL(MutexVector*) HeldMutexStack;
static MutexVector& heldMutexStack();
};
#endif
}
#endif