Skip to content

Commit ee89af8

Browse files
author
vladlosev
committed
Expressed the thread-safety annotations in code, replacing the existing comment-based system (by Aaron Jacobs).
git-svn-id: http://googletest.googlecode.com/svn/trunk@604 861a406c-534a-0410-8894-cb66d6ee9925
1 parent b4661bc commit ee89af8

File tree

5 files changed

+51
-36
lines changed

5 files changed

+51
-36
lines changed

include/gtest/gtest.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,11 +1107,13 @@ class GTEST_API_ UnitTest {
11071107

11081108
// Returns the TestCase object for the test that's currently running,
11091109
// or NULL if no test is running.
1110-
const TestCase* current_test_case() const;
1110+
const TestCase* current_test_case() const
1111+
GTEST_LOCK_EXCLUDED_(mutex_);
11111112

11121113
// Returns the TestInfo object for the test that's currently running,
11131114
// or NULL if no test is running.
1114-
const TestInfo* current_test_info() const;
1115+
const TestInfo* current_test_info() const
1116+
GTEST_LOCK_EXCLUDED_(mutex_);
11151117

11161118
// Returns the random seed used at the start of the current test run.
11171119
int random_seed() const;
@@ -1121,7 +1123,8 @@ class GTEST_API_ UnitTest {
11211123
// value-parameterized tests and instantiate and register them.
11221124
//
11231125
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
1124-
internal::ParameterizedTestCaseRegistry& parameterized_test_registry();
1126+
internal::ParameterizedTestCaseRegistry& parameterized_test_registry()
1127+
GTEST_LOCK_EXCLUDED_(mutex_);
11251128
#endif // GTEST_HAS_PARAM_TEST
11261129

11271130
// Gets the number of successful test cases.
@@ -1194,7 +1197,8 @@ class GTEST_API_ UnitTest {
11941197
const char* file_name,
11951198
int line_number,
11961199
const internal::String& message,
1197-
const internal::String& os_stack_trace);
1200+
const internal::String& os_stack_trace)
1201+
GTEST_LOCK_EXCLUDED_(mutex_);
11981202

11991203
// Adds a TestProperty to the current TestResult object. If the result already
12001204
// contains a property with the same key, the value will be updated.
@@ -1227,10 +1231,12 @@ class GTEST_API_ UnitTest {
12271231

12281232
// Pushes a trace defined by SCOPED_TRACE() on to the per-thread
12291233
// Google Test trace stack.
1230-
void PushGTestTrace(const internal::TraceInfo& trace);
1234+
void PushGTestTrace(const internal::TraceInfo& trace)
1235+
GTEST_LOCK_EXCLUDED_(mutex_);
12311236

12321237
// Pops a trace from the per-thread Google Test trace stack.
1233-
void PopGTestTrace();
1238+
void PopGTestTrace()
1239+
GTEST_LOCK_EXCLUDED_(mutex_);
12341240

12351241
// Protects mutable state in *impl_. This is mutable as some const
12361242
// methods need to lock it too.

include/gtest/internal/gtest-linked_ptr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ class linked_ptr_internal {
105105
// framework.
106106

107107
// Join an existing circle.
108-
// L < g_linked_ptr_mutex
109-
void join(linked_ptr_internal const* ptr) {
108+
void join(linked_ptr_internal const* ptr)
109+
GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) {
110110
MutexLock lock(&g_linked_ptr_mutex);
111111

112112
linked_ptr_internal const* p = ptr;
@@ -117,8 +117,8 @@ class linked_ptr_internal {
117117

118118
// Leave whatever circle we're part of. Returns true if we were the
119119
// last member of the circle. Once this is done, you can join() another.
120-
// L < g_linked_ptr_mutex
121-
bool depart() {
120+
bool depart()
121+
GTEST_LOCK_EXCLUDED_(g_linked_ptr_mutex) {
122122
MutexLock lock(&g_linked_ptr_mutex);
123123

124124
if (next_ == this) return true;

include/gtest/internal/gtest-port.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,6 +1789,10 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
17891789
#define GTEST_DEFINE_string_(name, default_val, doc) \
17901790
GTEST_API_ ::testing::internal::String GTEST_FLAG(name) = (default_val)
17911791

1792+
// Thread annotations
1793+
#define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
1794+
#define GTEST_LOCK_EXCLUDED_(locks)
1795+
17921796
// Parses 'str' for a 32-bit signed integer. If successful, writes the result
17931797
// to *value and returns true; otherwise leaves *value unchanged and returns
17941798
// false.

src/gtest-internal-inl.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,12 @@ class OsStackTraceGetterInterface {
438438
class OsStackTraceGetter : public OsStackTraceGetterInterface {
439439
public:
440440
OsStackTraceGetter() : caller_frame_(NULL) {}
441-
virtual String CurrentStackTrace(int max_depth, int skip_count);
441+
442+
virtual String CurrentStackTrace(int max_depth, int skip_count)
443+
GTEST_LOCK_EXCLUDED_(mutex_);
444+
442445
virtual void UponLeavingGTest();
446+
GTEST_LOCK_EXCLUDED_(mutex_);
443447

444448
// This string is inserted in place of stack frames that are part of
445449
// Google Test's implementation.

src/gtest.cc

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3528,8 +3528,8 @@ void StreamingListener::MakeConnection() {
35283528

35293529
// Pushes the given source file location and message onto a per-thread
35303530
// trace stack maintained by Google Test.
3531-
// L < UnitTest::mutex_
3532-
ScopedTrace::ScopedTrace(const char* file, int line, const Message& message) {
3531+
ScopedTrace::ScopedTrace(const char* file, int line, const Message& message)
3532+
GTEST_LOCK_EXCLUDED_(UnitTest::mutex_) {
35333533
TraceInfo trace;
35343534
trace.file = file;
35353535
trace.line = line;
@@ -3539,8 +3539,8 @@ ScopedTrace::ScopedTrace(const char* file, int line, const Message& message) {
35393539
}
35403540

35413541
// Pops the info pushed by the c'tor.
3542-
// L < UnitTest::mutex_
3543-
ScopedTrace::~ScopedTrace() {
3542+
ScopedTrace::~ScopedTrace()
3543+
GTEST_LOCK_EXCLUDED_(UnitTest::mutex_) {
35443544
UnitTest::GetInstance()->PopGTestTrace();
35453545
}
35463546

@@ -3554,14 +3554,14 @@ ScopedTrace::~ScopedTrace() {
35543554
// skip_count - the number of top frames to be skipped; doesn't count
35553555
// against max_depth.
35563556
//
3557-
// L < mutex_
3558-
// We use "L < mutex_" to denote that the function may acquire mutex_.
3559-
String OsStackTraceGetter::CurrentStackTrace(int, int) {
3557+
String OsStackTraceGetter::CurrentStackTrace(int /* max_depth */,
3558+
int /* skip_count */)
3559+
GTEST_LOCK_EXCLUDED_(mutex_) {
35603560
return String("");
35613561
}
35623562

3563-
// L < mutex_
3564-
void OsStackTraceGetter::UponLeavingGTest() {
3563+
void OsStackTraceGetter::UponLeavingGTest()
3564+
GTEST_LOCK_EXCLUDED_(mutex_) {
35653565
}
35663566

35673567
const char* const
@@ -3774,12 +3774,13 @@ Environment* UnitTest::AddEnvironment(Environment* env) {
37743774
// assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) eventually call
37753775
// this to report their results. The user code should use the
37763776
// assertion macros instead of calling this directly.
3777-
// L < mutex_
3778-
void UnitTest::AddTestPartResult(TestPartResult::Type result_type,
3779-
const char* file_name,
3780-
int line_number,
3781-
const internal::String& message,
3782-
const internal::String& os_stack_trace) {
3777+
void UnitTest::AddTestPartResult(
3778+
TestPartResult::Type result_type,
3779+
const char* file_name,
3780+
int line_number,
3781+
const internal::String& message,
3782+
const internal::String& os_stack_trace)
3783+
GTEST_LOCK_EXCLUDED_(mutex_) {
37833784
Message msg;
37843785
msg << message;
37853786

@@ -3912,16 +3913,16 @@ const char* UnitTest::original_working_dir() const {
39123913

39133914
// Returns the TestCase object for the test that's currently running,
39143915
// or NULL if no test is running.
3915-
// L < mutex_
3916-
const TestCase* UnitTest::current_test_case() const {
3916+
const TestCase* UnitTest::current_test_case() const
3917+
GTEST_LOCK_EXCLUDED_(mutex_) {
39173918
internal::MutexLock lock(&mutex_);
39183919
return impl_->current_test_case();
39193920
}
39203921

39213922
// Returns the TestInfo object for the test that's currently running,
39223923
// or NULL if no test is running.
3923-
// L < mutex_
3924-
const TestInfo* UnitTest::current_test_info() const {
3924+
const TestInfo* UnitTest::current_test_info() const
3925+
GTEST_LOCK_EXCLUDED_(mutex_) {
39253926
internal::MutexLock lock(&mutex_);
39263927
return impl_->current_test_info();
39273928
}
@@ -3932,9 +3933,9 @@ int UnitTest::random_seed() const { return impl_->random_seed(); }
39323933
#if GTEST_HAS_PARAM_TEST
39333934
// Returns ParameterizedTestCaseRegistry object used to keep track of
39343935
// value-parameterized tests and instantiate and register them.
3935-
// L < mutex_
39363936
internal::ParameterizedTestCaseRegistry&
3937-
UnitTest::parameterized_test_registry() {
3937+
UnitTest::parameterized_test_registry()
3938+
GTEST_LOCK_EXCLUDED_(mutex_) {
39383939
return impl_->parameterized_test_registry();
39393940
}
39403941
#endif // GTEST_HAS_PARAM_TEST
@@ -3951,15 +3952,15 @@ UnitTest::~UnitTest() {
39513952

39523953
// Pushes a trace defined by SCOPED_TRACE() on to the per-thread
39533954
// Google Test trace stack.
3954-
// L < mutex_
3955-
void UnitTest::PushGTestTrace(const internal::TraceInfo& trace) {
3955+
void UnitTest::PushGTestTrace(const internal::TraceInfo& trace)
3956+
GTEST_LOCK_EXCLUDED_(mutex_) {
39563957
internal::MutexLock lock(&mutex_);
39573958
impl_->gtest_trace_stack().push_back(trace);
39583959
}
39593960

39603961
// Pops a trace from the per-thread Google Test trace stack.
3961-
// L < mutex_
3962-
void UnitTest::PopGTestTrace() {
3962+
void UnitTest::PopGTestTrace()
3963+
GTEST_LOCK_EXCLUDED_(mutex_) {
39633964
internal::MutexLock lock(&mutex_);
39643965
impl_->gtest_trace_stack().pop_back();
39653966
}

0 commit comments

Comments
 (0)