зеркало из https://github.com/mozilla/gecko-dev.git
Bug 956899 - Add a std::lock_guard work-alike; r=froydnj
--HG-- extra : rebase_source : c80c16798e2785f642a735bf4a24f859e202bee7
This commit is contained in:
Родитель
e54e391f05
Коммит
9d131b35b6
|
@ -6,6 +6,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#include "jsapi-tests/tests.h"
|
#include "jsapi-tests/tests.h"
|
||||||
|
#include "threading/LockGuard.h"
|
||||||
#include "threading/Mutex.h"
|
#include "threading/Mutex.h"
|
||||||
|
|
||||||
BEGIN_TEST(testThreadingMutex)
|
BEGIN_TEST(testThreadingMutex)
|
||||||
|
@ -16,3 +17,11 @@ BEGIN_TEST(testThreadingMutex)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
END_TEST(testThreadingMutex)
|
END_TEST(testThreadingMutex)
|
||||||
|
|
||||||
|
BEGIN_TEST(testThreadingLockGuard)
|
||||||
|
{
|
||||||
|
js::Mutex mutex;
|
||||||
|
js::LockGuard<js::Mutex> guard(mutex);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
END_TEST(testThreadingLockGuard)
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||||
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||||
|
/* 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 threading_LockGuard_h
|
||||||
|
#define threading_LockGuard_h
|
||||||
|
|
||||||
|
namespace js {
|
||||||
|
|
||||||
|
template <typename Mutex>
|
||||||
|
class MOZ_RAII LockGuard
|
||||||
|
{
|
||||||
|
Mutex& lock;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit LockGuard(Mutex& aLock)
|
||||||
|
: lock(aLock)
|
||||||
|
{
|
||||||
|
lock.lock();
|
||||||
|
}
|
||||||
|
|
||||||
|
~LockGuard() {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace js
|
||||||
|
|
||||||
|
#endif // threading_LockGuard_h
|
Загрузка…
Ссылка в новой задаче