Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
4c11f25f
Commit
4c11f25f
authored
Oct 24, 2011
by
vladlosev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expressed the thread-safety annotations in code, replacing the existing…
Expressed the thread-safety annotations in code, replacing the existing comment-based system (by Aaron Jacobs).
parent
97ef1c70
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
36 deletions
+51
-36
gtest.h
include/gtest/gtest.h
+12
-6
gtest-linked_ptr.h
include/gtest/internal/gtest-linked_ptr.h
+4
-4
gtest-port.h
include/gtest/internal/gtest-port.h
+4
-0
gtest-internal-inl.h
src/gtest-internal-inl.h
+5
-1
gtest.cc
src/gtest.cc
+26
-25
No files found.
include/gtest/gtest.h
View file @
4c11f25f
...
@@ -1107,11 +1107,13 @@ class GTEST_API_ UnitTest {
...
@@ -1107,11 +1107,13 @@ class GTEST_API_ UnitTest {
// Returns the TestCase object for the test that's currently running,
// Returns the TestCase object for the test that's currently running,
// or NULL if no test is running.
// or NULL if no test is running.
const
TestCase
*
current_test_case
()
const
;
const
TestCase
*
current_test_case
()
const
GTEST_LOCK_EXCLUDED_
(
mutex_
);
// Returns the TestInfo object for the test that's currently running,
// Returns the TestInfo object for the test that's currently running,
// or NULL if no test is running.
// or NULL if no test is running.
const
TestInfo
*
current_test_info
()
const
;
const
TestInfo
*
current_test_info
()
const
GTEST_LOCK_EXCLUDED_
(
mutex_
);
// Returns the random seed used at the start of the current test run.
// Returns the random seed used at the start of the current test run.
int
random_seed
()
const
;
int
random_seed
()
const
;
...
@@ -1121,7 +1123,8 @@ class GTEST_API_ UnitTest {
...
@@ -1121,7 +1123,8 @@ class GTEST_API_ UnitTest {
// value-parameterized tests and instantiate and register them.
// value-parameterized tests and instantiate and register them.
//
//
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
// INTERNAL IMPLEMENTATION - DO NOT USE IN A USER PROGRAM.
internal
::
ParameterizedTestCaseRegistry
&
parameterized_test_registry
();
internal
::
ParameterizedTestCaseRegistry
&
parameterized_test_registry
()
GTEST_LOCK_EXCLUDED_
(
mutex_
);
#endif // GTEST_HAS_PARAM_TEST
#endif // GTEST_HAS_PARAM_TEST
// Gets the number of successful test cases.
// Gets the number of successful test cases.
...
@@ -1194,7 +1197,8 @@ class GTEST_API_ UnitTest {
...
@@ -1194,7 +1197,8 @@ class GTEST_API_ UnitTest {
const
char
*
file_name
,
const
char
*
file_name
,
int
line_number
,
int
line_number
,
const
internal
::
String
&
message
,
const
internal
::
String
&
message
,
const
internal
::
String
&
os_stack_trace
);
const
internal
::
String
&
os_stack_trace
)
GTEST_LOCK_EXCLUDED_
(
mutex_
);
// Adds a TestProperty to the current TestResult object. If the result already
// Adds a TestProperty to the current TestResult object. If the result already
// contains a property with the same key, the value will be updated.
// contains a property with the same key, the value will be updated.
...
@@ -1227,10 +1231,12 @@ class GTEST_API_ UnitTest {
...
@@ -1227,10 +1231,12 @@ class GTEST_API_ UnitTest {
// Pushes a trace defined by SCOPED_TRACE() on to the per-thread
// Pushes a trace defined by SCOPED_TRACE() on to the per-thread
// Google Test trace stack.
// Google Test trace stack.
void
PushGTestTrace
(
const
internal
::
TraceInfo
&
trace
);
void
PushGTestTrace
(
const
internal
::
TraceInfo
&
trace
)
GTEST_LOCK_EXCLUDED_
(
mutex_
);
// Pops a trace from the per-thread Google Test trace stack.
// Pops a trace from the per-thread Google Test trace stack.
void
PopGTestTrace
();
void
PopGTestTrace
()
GTEST_LOCK_EXCLUDED_
(
mutex_
);
// Protects mutable state in *impl_. This is mutable as some const
// Protects mutable state in *impl_. This is mutable as some const
// methods need to lock it too.
// methods need to lock it too.
...
...
include/gtest/internal/gtest-linked_ptr.h
View file @
4c11f25f
...
@@ -105,8 +105,8 @@ class linked_ptr_internal {
...
@@ -105,8 +105,8 @@ class linked_ptr_internal {
// framework.
// framework.
// Join an existing circle.
// Join an existing circle.
// L < g_linked_ptr_mutex
void
join
(
linked_ptr_internal
const
*
ptr
)
void
join
(
linked_ptr_internal
const
*
ptr
)
{
GTEST_LOCK_EXCLUDED_
(
g_linked_ptr_mutex
)
{
MutexLock
lock
(
&
g_linked_ptr_mutex
);
MutexLock
lock
(
&
g_linked_ptr_mutex
);
linked_ptr_internal
const
*
p
=
ptr
;
linked_ptr_internal
const
*
p
=
ptr
;
...
@@ -117,8 +117,8 @@ class linked_ptr_internal {
...
@@ -117,8 +117,8 @@ class linked_ptr_internal {
// Leave whatever circle we're part of. Returns true if we were the
// Leave whatever circle we're part of. Returns true if we were the
// last member of the circle. Once this is done, you can join() another.
// last member of the circle. Once this is done, you can join() another.
// L < g_linked_ptr_mutex
bool
depart
()
bool
depart
(
)
{
GTEST_LOCK_EXCLUDED_
(
g_linked_ptr_mutex
)
{
MutexLock
lock
(
&
g_linked_ptr_mutex
);
MutexLock
lock
(
&
g_linked_ptr_mutex
);
if
(
next_
==
this
)
return
true
;
if
(
next_
==
this
)
return
true
;
...
...
include/gtest/internal/gtest-port.h
View file @
4c11f25f
...
@@ -1789,6 +1789,10 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
...
@@ -1789,6 +1789,10 @@ typedef TypeWithSize<8>::Int TimeInMillis; // Represents time in milliseconds.
#define GTEST_DEFINE_string_(name, default_val, doc) \
#define GTEST_DEFINE_string_(name, default_val, doc) \
GTEST_API_ ::testing::internal::String GTEST_FLAG(name) = (default_val)
GTEST_API_ ::testing::internal::String GTEST_FLAG(name) = (default_val)
// Thread annotations
#define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)
#define GTEST_LOCK_EXCLUDED_(locks)
// Parses 'str' for a 32-bit signed integer. If successful, writes the result
// Parses 'str' for a 32-bit signed integer. If successful, writes the result
// to *value and returns true; otherwise leaves *value unchanged and returns
// to *value and returns true; otherwise leaves *value unchanged and returns
// false.
// false.
...
...
src/gtest-internal-inl.h
View file @
4c11f25f
...
@@ -438,8 +438,12 @@ class OsStackTraceGetterInterface {
...
@@ -438,8 +438,12 @@ class OsStackTraceGetterInterface {
class
OsStackTraceGetter
:
public
OsStackTraceGetterInterface
{
class
OsStackTraceGetter
:
public
OsStackTraceGetterInterface
{
public
:
public
:
OsStackTraceGetter
()
:
caller_frame_
(
NULL
)
{}
OsStackTraceGetter
()
:
caller_frame_
(
NULL
)
{}
virtual
String
CurrentStackTrace
(
int
max_depth
,
int
skip_count
);
virtual
String
CurrentStackTrace
(
int
max_depth
,
int
skip_count
)
GTEST_LOCK_EXCLUDED_
(
mutex_
);
virtual
void
UponLeavingGTest
();
virtual
void
UponLeavingGTest
();
GTEST_LOCK_EXCLUDED_
(
mutex_
);
// This string is inserted in place of stack frames that are part of
// This string is inserted in place of stack frames that are part of
// Google Test's implementation.
// Google Test's implementation.
...
...
src/gtest.cc
View file @
4c11f25f
...
@@ -3528,8 +3528,8 @@ void StreamingListener::MakeConnection() {
...
@@ -3528,8 +3528,8 @@ void StreamingListener::MakeConnection() {
// Pushes the given source file location and message onto a per-thread
// Pushes the given source file location and message onto a per-thread
// trace stack maintained by Google Test.
// trace stack maintained by Google Test.
// L < UnitTest::mutex_
ScopedTrace
::
ScopedTrace
(
const
char
*
file
,
int
line
,
const
Message
&
message
)
ScopedTrace
::
ScopedTrace
(
const
char
*
file
,
int
line
,
const
Message
&
message
)
{
GTEST_LOCK_EXCLUDED_
(
UnitTest
::
mutex_
)
{
TraceInfo
trace
;
TraceInfo
trace
;
trace
.
file
=
file
;
trace
.
file
=
file
;
trace
.
line
=
line
;
trace
.
line
=
line
;
...
@@ -3539,8 +3539,8 @@ ScopedTrace::ScopedTrace(const char* file, int line, const Message& message) {
...
@@ -3539,8 +3539,8 @@ ScopedTrace::ScopedTrace(const char* file, int line, const Message& message) {
}
}
// Pops the info pushed by the c'tor.
// Pops the info pushed by the c'tor.
// L < UnitTest::mutex_
ScopedTrace
::~
ScopedTrace
()
ScopedTrace
::~
ScopedTrace
(
)
{
GTEST_LOCK_EXCLUDED_
(
UnitTest
::
mutex_
)
{
UnitTest
::
GetInstance
()
->
PopGTestTrace
();
UnitTest
::
GetInstance
()
->
PopGTestTrace
();
}
}
...
@@ -3554,14 +3554,14 @@ ScopedTrace::~ScopedTrace() {
...
@@ -3554,14 +3554,14 @@ ScopedTrace::~ScopedTrace() {
// skip_count - the number of top frames to be skipped; doesn't count
// skip_count - the number of top frames to be skipped; doesn't count
// against max_depth.
// against max_depth.
//
//
// L < mutex_
String
OsStackTraceGetter
::
CurrentStackTrace
(
int
/* max_depth */
,
// We use "L < mutex_" to denote that the function may acquire mutex_.
int
/* skip_count */
)
String
OsStackTraceGetter
::
CurrentStackTrace
(
int
,
int
)
{
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
return
String
(
""
);
return
String
(
""
);
}
}
// L < mutex_
void
OsStackTraceGetter
::
UponLeavingGTest
()
void
OsStackTraceGetter
::
UponLeavingGTest
(
)
{
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
}
}
const
char
*
const
const
char
*
const
...
@@ -3774,12 +3774,13 @@ Environment* UnitTest::AddEnvironment(Environment* env) {
...
@@ -3774,12 +3774,13 @@ Environment* UnitTest::AddEnvironment(Environment* env) {
// assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) eventually call
// assertion macros (e.g. ASSERT_TRUE, EXPECT_EQ, etc) eventually call
// this to report their results. The user code should use the
// this to report their results. The user code should use the
// assertion macros instead of calling this directly.
// assertion macros instead of calling this directly.
// L < mutex_
void
UnitTest
::
AddTestPartResult
(
void
UnitTest
::
AddTestPartResult
(
TestPartResult
::
Type
result_type
,
TestPartResult
::
Type
result_type
,
const
char
*
file_name
,
const
char
*
file_name
,
int
line_number
,
int
line_number
,
const
internal
::
String
&
message
,
const
internal
::
String
&
message
,
const
internal
::
String
&
os_stack_trace
)
{
const
internal
::
String
&
os_stack_trace
)
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
Message
msg
;
Message
msg
;
msg
<<
message
;
msg
<<
message
;
...
@@ -3912,16 +3913,16 @@ const char* UnitTest::original_working_dir() const {
...
@@ -3912,16 +3913,16 @@ const char* UnitTest::original_working_dir() const {
// Returns the TestCase object for the test that's currently running,
// Returns the TestCase object for the test that's currently running,
// or NULL if no test is running.
// or NULL if no test is running.
// L < mutex_
const
TestCase
*
UnitTest
::
current_test_case
()
const
const
TestCase
*
UnitTest
::
current_test_case
()
const
{
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
internal
::
MutexLock
lock
(
&
mutex_
);
internal
::
MutexLock
lock
(
&
mutex_
);
return
impl_
->
current_test_case
();
return
impl_
->
current_test_case
();
}
}
// Returns the TestInfo object for the test that's currently running,
// Returns the TestInfo object for the test that's currently running,
// or NULL if no test is running.
// or NULL if no test is running.
// L < mutex_
const
TestInfo
*
UnitTest
::
current_test_info
()
const
const
TestInfo
*
UnitTest
::
current_test_info
()
const
{
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
internal
::
MutexLock
lock
(
&
mutex_
);
internal
::
MutexLock
lock
(
&
mutex_
);
return
impl_
->
current_test_info
();
return
impl_
->
current_test_info
();
}
}
...
@@ -3932,9 +3933,9 @@ int UnitTest::random_seed() const { return impl_->random_seed(); }
...
@@ -3932,9 +3933,9 @@ int UnitTest::random_seed() const { return impl_->random_seed(); }
#if GTEST_HAS_PARAM_TEST
#if GTEST_HAS_PARAM_TEST
// Returns ParameterizedTestCaseRegistry object used to keep track of
// Returns ParameterizedTestCaseRegistry object used to keep track of
// value-parameterized tests and instantiate and register them.
// value-parameterized tests and instantiate and register them.
// L < mutex_
internal
::
ParameterizedTestCaseRegistry
&
internal
::
ParameterizedTestCaseRegistry
&
UnitTest
::
parameterized_test_registry
()
{
UnitTest
::
parameterized_test_registry
()
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
return
impl_
->
parameterized_test_registry
();
return
impl_
->
parameterized_test_registry
();
}
}
#endif // GTEST_HAS_PARAM_TEST
#endif // GTEST_HAS_PARAM_TEST
...
@@ -3951,15 +3952,15 @@ UnitTest::~UnitTest() {
...
@@ -3951,15 +3952,15 @@ UnitTest::~UnitTest() {
// Pushes a trace defined by SCOPED_TRACE() on to the per-thread
// Pushes a trace defined by SCOPED_TRACE() on to the per-thread
// Google Test trace stack.
// Google Test trace stack.
// L < mutex_
void
UnitTest
::
PushGTestTrace
(
const
internal
::
TraceInfo
&
trace
)
void
UnitTest
::
PushGTestTrace
(
const
internal
::
TraceInfo
&
trace
)
{
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
internal
::
MutexLock
lock
(
&
mutex_
);
internal
::
MutexLock
lock
(
&
mutex_
);
impl_
->
gtest_trace_stack
().
push_back
(
trace
);
impl_
->
gtest_trace_stack
().
push_back
(
trace
);
}
}
// Pops a trace from the per-thread Google Test trace stack.
// Pops a trace from the per-thread Google Test trace stack.
// L < mutex_
void
UnitTest
::
PopGTestTrace
()
void
UnitTest
::
PopGTestTrace
(
)
{
GTEST_LOCK_EXCLUDED_
(
mutex_
)
{
internal
::
MutexLock
lock
(
&
mutex_
);
internal
::
MutexLock
lock
(
&
mutex_
);
impl_
->
gtest_trace_stack
().
pop_back
();
impl_
->
gtest_trace_stack
().
pop_back
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment