summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Leinartas <mleinartas@twitter.com>2022-06-17 19:40:04 +0200
committerJens Geyer <jensg@apache.org>2022-06-21 22:27:41 +0200
commit3a6f8a228f7008f033d609bdef2df952e2e2fc54 (patch)
treedaa7bda2a3470ddf5f08fde67d1ea78e5bb46407
parent7628392dff65d747a026fd5183466c4460047c92 (diff)
downloadthrift-3a6f8a228f7008f033d609bdef2df952e2e2fc54.tar.gz
THRIFT-5599: contrib/fb303 does not compile after C++ library refactorings
Patch: Michael Leinartas This closes #2624
-rw-r--r--contrib/fb303/cpp/FacebookBase.cpp36
-rw-r--r--contrib/fb303/cpp/FacebookBase.h5
-rw-r--r--contrib/fb303/cpp/Makefile.am4
3 files changed, 20 insertions, 25 deletions
diff --git a/contrib/fb303/cpp/FacebookBase.cpp b/contrib/fb303/cpp/FacebookBase.cpp
index eb2e63cc5..d6a44a2af 100644
--- a/contrib/fb303/cpp/FacebookBase.cpp
+++ b/contrib/fb303/cpp/FacebookBase.cpp
@@ -47,74 +47,70 @@ void FacebookBase::getOptions(std::map<std::string, std::string> & _return) {
}
int64_t FacebookBase::incrementCounter(const std::string& key, int64_t amount) {
- counters_.acquireRead();
+ counters_.lock();
// if we didn't find the key, we need to write lock the whole map to create it
ReadWriteCounterMap::iterator it = counters_.find(key);
if (it == counters_.end()) {
- counters_.release();
- counters_.acquireWrite();
// we need to check again to make sure someone didn't create this key
// already while we released the lock
it = counters_.find(key);
if(it == counters_.end()){
counters_[key].value = amount;
- counters_.release();
+ counters_.unlock();
return amount;
}
}
- it->second.acquireWrite();
+ it->second.lock();
int64_t count = it->second.value + amount;
it->second.value = count;
- it->second.release();
- counters_.release();
+ it->second.unlock();
+ counters_.unlock();
return count;
}
int64_t FacebookBase::setCounter(const std::string& key, int64_t value) {
- counters_.acquireRead();
+ counters_.lock();
// if we didn't find the key, we need to write lock the whole map to create it
ReadWriteCounterMap::iterator it = counters_.find(key);
if (it == counters_.end()) {
- counters_.release();
- counters_.acquireWrite();
counters_[key].value = value;
- counters_.release();
+ counters_.unlock();
return value;
}
- it->second.acquireWrite();
+ it->second.lock();
it->second.value = value;
- it->second.release();
- counters_.release();
+ it->second.unlock();
+ counters_.unlock();
return value;
}
void FacebookBase::getCounters(std::map<std::string, int64_t>& _return) {
// we need to lock the whole thing and actually build the map since we don't
// want our read/write structure to go over the wire
- counters_.acquireRead();
+ counters_.lock();
for(ReadWriteCounterMap::iterator it = counters_.begin();
it != counters_.end(); ++it)
{
_return[it->first] = it->second.value;
}
- counters_.release();
+ counters_.unlock();
}
int64_t FacebookBase::getCounter(const std::string& key) {
int64_t rv = 0;
- counters_.acquireRead();
+ counters_.lock();
ReadWriteCounterMap::iterator it = counters_.find(key);
if (it != counters_.end()) {
- it->second.acquireRead();
+ it->second.lock();
rv = it->second.value;
- it->second.release();
+ it->second.unlock();
}
- counters_.release();
+ counters_.unlock();
return rv;
}
diff --git a/contrib/fb303/cpp/FacebookBase.h b/contrib/fb303/cpp/FacebookBase.h
index e0be4bf2e..0e4107db2 100644
--- a/contrib/fb303/cpp/FacebookBase.h
+++ b/contrib/fb303/cpp/FacebookBase.h
@@ -33,11 +33,10 @@
namespace facebook { namespace fb303 {
using apache::thrift::concurrency::Mutex;
-using apache::thrift::concurrency::ReadWriteMutex;
using apache::thrift::server::TServer;
-struct ReadWriteInt : ReadWriteMutex {int64_t value;};
-struct ReadWriteCounterMap : ReadWriteMutex,
+struct ReadWriteInt : Mutex {int64_t value;};
+struct ReadWriteCounterMap : Mutex,
std::map<std::string, ReadWriteInt> {};
/**
diff --git a/contrib/fb303/cpp/Makefile.am b/contrib/fb303/cpp/Makefile.am
index 748d3298d..0d68b4ede 100644
--- a/contrib/fb303/cpp/Makefile.am
+++ b/contrib/fb303/cpp/Makefile.am
@@ -47,7 +47,7 @@ AM_CPPFLAGS += $(FB_CPPFLAGS) $(DEBUG_CPPFLAGS)
# Use <progname|libname>_<FLAG> to set prog / lib specific flag s
# foo_CXXFLAGS foo_CPPFLAGS foo_LDFLAGS foo_LDADD
-fb303_lib = gen-cpp/FacebookService.cpp gen-cpp/fb303_constants.cpp gen-cpp/fb303_types.cpp FacebookBase.cpp ServiceTracker.cpp
+fb303_lib = gen-cpp/FacebookService.cpp gen-cpp/fb303_types.cpp FacebookBase.cpp ServiceTracker.cpp
# Static -- multiple libraries can be defined
if STATIC
@@ -71,7 +71,7 @@ endif
$(eval $(call thrift_template,.,../if/fb303.thrift,-I $(thrift_home)/share --gen cpp:pure_enums ))
include_fb303dir = $(includedir)/thrift/fb303
-include_fb303_HEADERS = FacebookBase.h ServiceTracker.h gen-cpp/FacebookService.h gen-cpp/fb303_constants.h gen-cpp/fb303_types.h
+include_fb303_HEADERS = FacebookBase.h ServiceTracker.h gen-cpp/FacebookService.h gen-cpp/fb303_types.h
include_fb303ifdir = $(prefix)/share/fb303/if
include_fb303if_HEADERS = ../if/fb303.thrift