1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "src/base/platform/mutex.h"
7 #include "testing/gtest/include/gtest/gtest.h"
12 TEST(Mutex, LockGuardMutex) {
14 { LockGuard<Mutex> lock_guard(&mutex); }
15 { LockGuard<Mutex> lock_guard(&mutex); }
19 TEST(Mutex, LockGuardRecursiveMutex) {
20 RecursiveMutex recursive_mutex;
21 { LockGuard<RecursiveMutex> lock_guard(&recursive_mutex); }
23 LockGuard<RecursiveMutex> lock_guard1(&recursive_mutex);
24 LockGuard<RecursiveMutex> lock_guard2(&recursive_mutex);
29 TEST(Mutex, LockGuardLazyMutex) {
30 LazyMutex lazy_mutex = LAZY_MUTEX_INITIALIZER;
31 { LockGuard<Mutex> lock_guard(lazy_mutex.Pointer()); }
32 { LockGuard<Mutex> lock_guard(lazy_mutex.Pointer()); }
36 TEST(Mutex, LockGuardLazyRecursiveMutex) {
37 LazyRecursiveMutex lazy_recursive_mutex = LAZY_RECURSIVE_MUTEX_INITIALIZER;
38 { LockGuard<RecursiveMutex> lock_guard(lazy_recursive_mutex.Pointer()); }
40 LockGuard<RecursiveMutex> lock_guard1(lazy_recursive_mutex.Pointer());
41 LockGuard<RecursiveMutex> lock_guard2(lazy_recursive_mutex.Pointer());
46 TEST(Mutex, MultipleMutexes) {
67 TEST(Mutex, MultipleRecursiveMutexes) {
68 RecursiveMutex recursive_mutex1;
69 RecursiveMutex recursive_mutex2;
71 recursive_mutex1.Lock();
72 recursive_mutex2.Lock();
73 EXPECT_TRUE(recursive_mutex1.TryLock());
74 EXPECT_TRUE(recursive_mutex2.TryLock());
75 recursive_mutex1.Unlock();
76 recursive_mutex1.Unlock();
77 recursive_mutex2.Unlock();
78 recursive_mutex2.Unlock();
80 recursive_mutex1.Lock();
81 EXPECT_TRUE(recursive_mutex1.TryLock());
82 recursive_mutex2.Lock();
83 EXPECT_TRUE(recursive_mutex2.TryLock());
84 recursive_mutex2.Unlock();
85 recursive_mutex1.Unlock();
86 recursive_mutex2.Unlock();
87 recursive_mutex1.Unlock();