mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-26 11:45:37 +00:00
Back out changeset 1364b664788a (bug 1257019) for check_spidermonkey_style.py failures
CLOSED TREE
This commit is contained in:
parent
b0bc1ab435
commit
6705425981
@ -34,17 +34,3 @@ BEGIN_TEST(testThreadingUnlockGuard)
|
||||
return true;
|
||||
}
|
||||
END_TEST(testThreadingUnlockGuard)
|
||||
|
||||
BEGIN_TEST(testThreadingMoveMutex)
|
||||
{
|
||||
js::Mutex mutex;
|
||||
mutex.lock();
|
||||
mutex.unlock();
|
||||
|
||||
js::Mutex another(mozilla::Move(mutex));
|
||||
another.lock();
|
||||
another.unlock();
|
||||
|
||||
return true;
|
||||
}
|
||||
END_TEST(testThreadingMoveMutex)
|
||||
|
@ -7,12 +7,7 @@
|
||||
#ifndef threading_Mutex_h
|
||||
#define threading_Mutex_h
|
||||
|
||||
#include <new>
|
||||
#include <string.h>
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/Move.h"
|
||||
|
||||
namespace js {
|
||||
|
||||
@ -27,29 +22,28 @@ public:
|
||||
void lock();
|
||||
void unlock();
|
||||
|
||||
Mutex(Mutex&& rhs)
|
||||
: platformData_(rhs.platformData_)
|
||||
{
|
||||
MOZ_ASSERT(this != &rhs, "self move disallowed!");
|
||||
rhs.platformData_ = nullptr;
|
||||
}
|
||||
|
||||
Mutex& operator=(Mutex&& rhs) {
|
||||
this->~Mutex();
|
||||
new (this) Mutex(mozilla::Move(rhs));
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
Mutex(const Mutex&) = delete;
|
||||
void operator=(const Mutex&) = delete;
|
||||
Mutex(Mutex&&) = delete;
|
||||
void operator=(Mutex&&) = delete;
|
||||
|
||||
PlatformData* platformData() {
|
||||
MOZ_ASSERT(platformData_);
|
||||
return platformData_;
|
||||
};
|
||||
PlatformData* platformData();
|
||||
|
||||
PlatformData* platformData_;
|
||||
// Linux and maybe other platforms define the storage size of pthread_mutex_t in
|
||||
// bytes. However, we must define it as an array of void pointers to ensure
|
||||
// proper alignment.
|
||||
#if defined(__APPLE__) && defined(__MACH__) && defined(__i386__)
|
||||
void* platformData_[11];
|
||||
#elif defined(__APPLE__) && defined(__MACH__) && defined(__amd64__)
|
||||
void* platformData_[8];
|
||||
#elif defined(__linux__)
|
||||
void* platformData_[40 / sizeof(void*)];
|
||||
#elif defined(_WIN32)
|
||||
void* platformData_[6];
|
||||
#else
|
||||
void* platformData_[64 / sizeof(void*)];
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace js
|
||||
|
@ -4,32 +4,23 @@
|
||||
* 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/. */
|
||||
|
||||
#include <pthread.h>
|
||||
#include "mozilla/Assertions.h"
|
||||
|
||||
#include "js/Utility.h"
|
||||
#include <pthread.h>
|
||||
|
||||
#include "threading/Mutex.h"
|
||||
#include "threading/posix/MutexPlatformData.h"
|
||||
|
||||
js::Mutex::Mutex()
|
||||
{
|
||||
AutoEnterOOMUnsafeRegion oom;
|
||||
platformData_ = js_new<PlatformData>();
|
||||
if (!platformData_)
|
||||
oom.crash("js::Mutex::Mutex");
|
||||
|
||||
int r = pthread_mutex_init(&platformData()->ptMutex, NULL);
|
||||
MOZ_RELEASE_ASSERT(r == 0);
|
||||
}
|
||||
|
||||
js::Mutex::~Mutex()
|
||||
{
|
||||
if (!platformData_)
|
||||
return;
|
||||
|
||||
int r = pthread_mutex_destroy(&platformData()->ptMutex);
|
||||
MOZ_RELEASE_ASSERT(r == 0);
|
||||
js_delete(platformData());
|
||||
}
|
||||
|
||||
void
|
||||
@ -45,3 +36,11 @@ js::Mutex::unlock()
|
||||
int r = pthread_mutex_unlock(&platformData()->ptMutex);
|
||||
MOZ_RELEASE_ASSERT(r == 0);
|
||||
}
|
||||
|
||||
js::Mutex::PlatformData*
|
||||
js::Mutex::platformData()
|
||||
{
|
||||
static_assert(sizeof(platformData_) >= sizeof(PlatformData),
|
||||
"platformData_ is too small");
|
||||
return reinterpret_cast<PlatformData*>(platformData_);
|
||||
}
|
||||
|
@ -4,12 +4,11 @@
|
||||
* 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/. */
|
||||
|
||||
#include "mozilla/Assertions.h"
|
||||
#include "mozilla/DebugOnly.h"
|
||||
|
||||
#include "jswin.h"
|
||||
|
||||
#include "js/Utility.h"
|
||||
|
||||
#include "threading/Mutex.h"
|
||||
#include "threading/windows/MutexPlatformData.h"
|
||||
|
||||
@ -44,11 +43,6 @@ static MutexNativeImports NativeImports;
|
||||
|
||||
js::Mutex::Mutex()
|
||||
{
|
||||
AutoEnterOOMUnsafeRegion oom;
|
||||
platformData_ = js_new<PlatformData>();
|
||||
if (!platformData_)
|
||||
oom.crash("js::Mutex::Mutex");
|
||||
|
||||
// This number was adopted from NSPR.
|
||||
const static DWORD LockSpinCount = 1500;
|
||||
BOOL r;
|
||||
@ -65,11 +59,7 @@ js::Mutex::Mutex()
|
||||
|
||||
js::Mutex::~Mutex()
|
||||
{
|
||||
if (!platformData_)
|
||||
return;
|
||||
|
||||
DeleteCriticalSection(&platformData()->criticalSection);
|
||||
js_delete(platformData());
|
||||
}
|
||||
|
||||
void
|
||||
@ -83,3 +73,11 @@ js::Mutex::unlock()
|
||||
{
|
||||
LeaveCriticalSection(&platformData()->criticalSection);
|
||||
}
|
||||
|
||||
js::Mutex::PlatformData*
|
||||
js::Mutex::platformData()
|
||||
{
|
||||
static_assert(sizeof(platformData_) >= sizeof(PlatformData),
|
||||
"platformData_ is too small");
|
||||
return reinterpret_cast<PlatformData*>(platformData_);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user