1 // Copyright 2018 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "thread_annotations.h"
7 #include "base/memory/raw_ref.h"
8 #include "testing/gtest/include/gtest/gtest.h"
14 void Acquire() EXCLUSIVE_LOCK_FUNCTION() {}
15 void Release() UNLOCK_FUNCTION() {}
18 class SCOPED_LOCKABLE AutoLock {
20 AutoLock(Lock& lock) EXCLUSIVE_LOCK_FUNCTION(lock) : lock_(lock) {
23 ~AutoLock() UNLOCK_FUNCTION() { lock_->Release(); }
26 const raw_ref<Lock> lock_;
31 void ExplicitIncrement();
32 void ImplicitIncrement();
36 int counter_ GUARDED_BY(lock_);
39 void ThreadSafe::ExplicitIncrement() {
45 void ThreadSafe::ImplicitIncrement() {
46 AutoLock auto_lock(lock_);
50 TEST(ThreadAnnotationsTest, ExplicitIncrement) {
51 ThreadSafe thread_safe;
52 thread_safe.ExplicitIncrement();
54 TEST(ThreadAnnotationsTest, ImplicitIncrement) {
55 ThreadSafe thread_safe;
56 thread_safe.ImplicitIncrement();
59 } // anonymous namespace