summaryrefslogtreecommitdiff
path: root/src/gflags.cc
diff options
context:
space:
mode:
authorCraig Silverstein <csilvers+gflags@google.com>2007-08-15 19:44:54 +0000
committerCraig Silverstein <csilvers+gflags@google.com>2007-08-15 19:44:54 +0000
commiteb2083998d18265a001e6bd8bf08d56d27ed8061 (patch)
tree64c973c163429376fa0fd5bf036f82ad9deb535f /src/gflags.cc
parent2b66a84406d61c6c18447c0dd1ebcad17280453f (diff)
downloadgflags-eb2083998d18265a001e6bd8bf08d56d27ed8061.tar.gz
gflags-eb2083998d18265a001e6bd8bf08d56d27ed8061.tar.bz2
gflags-eb2083998d18265a001e6bd8bf08d56d27ed8061.zip
Wed Aug 15 07:35:51 2007 Google Inc. <opensource@google.com>
* google-gflags: version 0.6 * Deal correctly with case that libpthread is not linked in (csilvers) * Update Makefile/tests so we pass "make distcheck" (csilvers) * Document and test that last assignment to a flag wins (wan) git-svn-id: https://gflags.googlecode.com/svn/trunk@17 6586e3c6-dcc4-952a-343f-ff74eb82781d
Diffstat (limited to 'src/gflags.cc')
-rw-r--r--src/gflags.cc24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/gflags.cc b/src/gflags.cc
index 54956a3..1210434 100644
--- a/src/gflags.cc
+++ b/src/gflags.cc
@@ -367,27 +367,20 @@ CommandLineFlag::~CommandLineFlag() {
const char* CommandLineFlag::CleanFileName() const {
// Compute top-level directory & file that this appears in
- // search full path backwards. Set kMaxSlashes = 5,
- // as the current code has <= 4 levels of dirs.
- // E.g. .../froogle/wrapping/autowrap/clustering/*.cc
- // Also, stop going backwards at "/google3/"; and skip by the first slash.
+ // search full path backwards.
+ // Stop going backwards at kGoogle; and skip by the first slash.
// E.g.
// filename_where_defined = "froogle/wrapping/autowrap/clustering/**.cc"
// filename_where_defined = "file/util/fileutil.cc"
- static const int kMaxSlashes = 5; // one more than max dir levels
static const char kGoogle[] = ""; // can set this to whatever
if (sizeof(kGoogle)-1 == 0) // no prefix to strip
return filename();
const char* clean_name = filename() + strlen(filename()) - 1;
- int slashes = 0;
while ( clean_name > filename() ) {
if (*clean_name == PATH_SEPARATOR) {
- ++slashes;
- if (slashes == kMaxSlashes) {
- break; // no dirs now are deeper than this
- } else if (strncmp(clean_name, kGoogle, sizeof(kGoogle)-1) == 0) {
+ if (strncmp(clean_name, kGoogle, sizeof(kGoogle)-1) == 0) {
// ".../google/base/logging.cc" ==> "base/logging.cc"
clean_name += sizeof(kGoogle)-1; // past "/google/"
break;
@@ -486,6 +479,7 @@ class FlagRegistry {
pthread_mutex_t lock_;
static FlagRegistry* global_registry_; // a singleton registry
static pthread_once_t global_registry_once_;
+ static int global_registry_once_nothreads_; // when we don't link pthreads
static void InitGlobalRegistry();
@@ -636,13 +630,21 @@ bool FlagRegistry::SetFlagLocked(CommandLineFlag* flag,
// Get the singleton FlagRegistry object
FlagRegistry* FlagRegistry::global_registry_ = NULL;
pthread_once_t FlagRegistry::global_registry_once_ = PTHREAD_ONCE_INIT;
+int FlagRegistry::global_registry_once_nothreads_ = 0;
void FlagRegistry::InitGlobalRegistry() {
global_registry_ = new FlagRegistry;
}
+// We want to use pthread_once here, for safety, but have to worry about
+// whether libpthread is linked in or not.
FlagRegistry* FlagRegistry::GlobalRegistry() {
- pthread_once(&global_registry_once_, &FlagRegistry::InitGlobalRegistry);
+ if (pthread_once) { // means we're running with pthreads
+ pthread_once(&global_registry_once_, &FlagRegistry::InitGlobalRegistry);
+ } else { // not running with pthreads: we're the only thread
+ if (global_registry_once_nothreads_++ == 0)
+ InitGlobalRegistry();
+ }
return global_registry_;
}