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
9a56024c
Commit
9a56024c
authored
Apr 02, 2012
by
jgm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for platforms where pthread_t is a struct rather than an integral
type.
parent
f0b86fc3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
8 deletions
+23
-8
internal_utils.cmake
cmake/internal_utils.cmake
+2
-1
gtest-port.h
include/gtest/internal/gtest-port.h
+21
-7
No files found.
cmake/internal_utils.cmake
View file @
9a56024c
...
...
@@ -79,7 +79,8 @@ macro(config_compiler_and_linker)
# whether RTTI is enabled. Therefore we define GTEST_HAS_RTTI
# explicitly.
set
(
cxx_no_rtti_flags
"-fno-rtti -DGTEST_HAS_RTTI=0"
)
set
(
cxx_strict_flags
"-Wextra"
)
set
(
cxx_strict_flags
"-Wextra -Wno-unused-parameter -Wno-missing-field-initializers"
)
elseif
(
CMAKE_CXX_COMPILER_ID STREQUAL
"SunPro"
)
set
(
cxx_exception_flags
"-features=except"
)
# Sun Pro doesn't provide macros to indicate whether exceptions and
...
...
include/gtest/internal/gtest-port.h
View file @
9a56024c
...
...
@@ -1240,21 +1240,23 @@ class MutexBase {
void
Lock
()
{
GTEST_CHECK_POSIX_SUCCESS_
(
pthread_mutex_lock
(
&
mutex_
));
owner_
=
pthread_self
();
has_owner_
=
true
;
}
// Releases this mutex.
void
Unlock
()
{
// We don't protect writing to owner_ here, as it's the caller's
// responsibility to ensure that the current thread holds the
// Since the lock is being released the owner_ field should no longer be
// considered valid. We don't protect writing to has_owner_ here, as it's
// the caller's responsibility to ensure that the current thread holds the
// mutex when this is called.
owner_
=
0
;
has_owner_
=
false
;
GTEST_CHECK_POSIX_SUCCESS_
(
pthread_mutex_unlock
(
&
mutex_
));
}
// Does nothing if the current thread holds the mutex. Otherwise, crashes
// with high probability.
void
AssertHeld
()
const
{
GTEST_CHECK_
(
owner_
==
pthread_self
(
))
GTEST_CHECK_
(
has_owner_
&&
pthread_equal
(
owner_
,
pthread_self
()
))
<<
"The current thread is not holding the mutex @"
<<
this
;
}
...
...
@@ -1265,7 +1267,14 @@ class MutexBase {
// have to be public.
public
:
pthread_mutex_t
mutex_
;
// The underlying pthread mutex.
pthread_t
owner_
;
// The thread holding the mutex; 0 means no one holds it.
// has_owner_ indicates whether the owner_ field below contains a valid thread
// ID and is therefore safe to inspect (e.g., to use in pthread_equal()). All
// accesses to the owner_ field should be protected by a check of this field.
// An alternative might be to memset() owner_ to all zeros, but there's no
// guarantee that a zero'd pthread_t is necessarily invalid or even different
// from pthread_self().
bool
has_owner_
;
pthread_t
owner_
;
// The thread holding the mutex.
};
// Forward-declares a static mutex.
...
...
@@ -1273,8 +1282,13 @@ class MutexBase {
extern ::testing::internal::MutexBase mutex
// Defines and statically (i.e. at link time) initializes a static mutex.
// The initialization list here does not explicitly initialize each field,
// instead relying on default initialization for the unspecified fields. In
// particular, the owner_ field (a pthread_t) is not explicitly initialized.
// This allows initialization to work whether pthread_t is a scalar or struct.
// The flag -Wmissing-field-initializers must not be specified for this to work.
# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \
::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER,
0
}
::testing::internal::MutexBase mutex = { PTHREAD_MUTEX_INITIALIZER,
false
}
// The Mutex class can only be used for mutexes created at runtime. It
// shares its API with MutexBase otherwise.
...
...
@@ -1282,7 +1296,7 @@ class Mutex : public MutexBase {
public
:
Mutex
()
{
GTEST_CHECK_POSIX_SUCCESS_
(
pthread_mutex_init
(
&
mutex_
,
NULL
));
owner_
=
0
;
has_owner_
=
false
;
}
~
Mutex
()
{
GTEST_CHECK_POSIX_SUCCESS_
(
pthread_mutex_destroy
(
&
mutex_
));
...
...
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