From 0aefb5af158e35b2bea38c8d0c31e1d2e274fdbe Mon Sep 17 00:00:00 2001 From: Jesse Williamson Date: Wed, 26 Apr 2017 05:26:38 -0700 Subject: [PATCH] rgw: migrate atomic_t to std::atomic<> Signed-off-by: Jesse Williamson --- src/common/RefCountedObj.h | 5 +++++ src/rgw/rgw_bucket.cc | 4 ++-- src/rgw/rgw_bucket.h | 2 +- src/rgw/rgw_coroutine.cc | 17 +++++++++-------- src/rgw/rgw_coroutine.h | 11 +++++++---- src/rgw/rgw_cr_rados.cc | 4 ++-- src/rgw/rgw_cr_rados.h | 10 ++++++---- src/rgw/rgw_file.cc | 4 +++- src/rgw/rgw_file.h | 2 +- src/rgw/rgw_gc.cc | 4 ++-- src/rgw/rgw_gc.h | 5 +++-- src/rgw/rgw_http_client.cc | 16 +++++++++------- src/rgw/rgw_http_client.h | 9 +++++---- src/rgw/rgw_keystone.cc | 2 +- src/rgw/rgw_keystone.h | 6 ++++-- src/rgw/rgw_lc.cc | 4 ++-- src/rgw/rgw_lc.h | 5 +++-- src/rgw/rgw_loadgen_process.cc | 12 +++++++----- src/rgw/rgw_main.cc | 5 +++-- src/rgw/rgw_object_expirer_core.cc | 4 ++-- src/rgw/rgw_object_expirer_core.h | 5 ++++- src/rgw/rgw_process.h | 4 +++- src/rgw/rgw_quota.cc | 8 +++++--- src/rgw/rgw_quota.h | 4 ++-- src/rgw/rgw_rados.cc | 28 ++++++++++++++++------------ src/rgw/rgw_rados.h | 6 +++--- src/rgw/rgw_request.h | 7 +++++-- src/rgw/rgw_rest_conn.cc | 4 ++-- src/rgw/rgw_rest_conn.h | 3 ++- src/rgw/rgw_sync.cc | 10 +++++----- src/rgw/rgw_sync.h | 6 ++++-- 31 files changed, 128 insertions(+), 88 deletions(-) diff --git a/src/common/RefCountedObj.h b/src/common/RefCountedObj.h index 2da83d1a760..6099bfff717 100644 --- a/src/common/RefCountedObj.h +++ b/src/common/RefCountedObj.h @@ -21,6 +21,11 @@ #include "common/ceph_context.h" #include "common/valgrind.h" +#include + +// re-include our assert to clobber the system one; fix dout: +#include "include/assert.h" + struct RefCountedObject { private: mutable atomic_t nref; diff --git a/src/rgw/rgw_bucket.cc b/src/rgw/rgw_bucket.cc index 5e0548afb79..015aab1d69a 100644 --- a/src/rgw/rgw_bucket.cc +++ b/src/rgw/rgw_bucket.cc @@ -1950,11 +1950,11 @@ int RGWDataChangesLog::trim_entries(const real_time& start_time, const real_time bool RGWDataChangesLog::going_down() { - return (down_flag.read() != 0); + return down_flag; } RGWDataChangesLog::~RGWDataChangesLog() { - down_flag.set(1); + down_flag = true; renew_thread->stop(); renew_thread->join(); delete renew_thread; diff --git a/src/rgw/rgw_bucket.h b/src/rgw/rgw_bucket.h index 3c6b399bdf7..09a5ae2e825 100644 --- a/src/rgw/rgw_bucket.h +++ b/src/rgw/rgw_bucket.h @@ -404,7 +404,7 @@ class RGWDataChangesLog { RWLock modified_lock; map > modified_shards; - atomic_t down_flag; + std::atomic down_flag = { false }; struct ChangeStatus { real_time cur_expiration; diff --git a/src/rgw/rgw_coroutine.cc b/src/rgw/rgw_coroutine.cc index 85ad290d020..4bb48da49dc 100644 --- a/src/rgw/rgw_coroutine.cc +++ b/src/rgw/rgw_coroutine.cc @@ -1,10 +1,11 @@ - #include "common/ceph_json.h" #include "rgw_coroutine.h" #include "rgw_boost_asio_yield.h" +// re-include our assert to clobber the system one; fix dout: +#include "include/assert.h" #define dout_subsys ceph_subsys_rgw @@ -68,7 +69,7 @@ int RGWCompletionManager::get_next(void **user_info) Mutex::Locker l(lock); while (complete_reqs.empty()) { cond.Wait(lock); - if (going_down.read() != 0) { + if (going_down) { return -ECANCELED; } } @@ -94,7 +95,7 @@ void RGWCompletionManager::go_down() for (auto cn : cns) { cn->unregister(); } - going_down.set(1); + going_down = true; cond.Signal(); } @@ -460,7 +461,7 @@ int RGWCoroutinesManager::run(list& stacks) bool canceled = false; // set on going_down RGWCoroutinesEnv env; - uint64_t run_context = run_context_count.inc(); + uint64_t run_context = ++run_context_count; lock.get_write(); set& context_stacks = run_contexts[run_context]; @@ -475,7 +476,7 @@ int RGWCoroutinesManager::run(list& stacks) env.manager = this; env.scheduled_stacks = &scheduled_stacks; - for (list::iterator iter = scheduled_stacks.begin(); iter != scheduled_stacks.end() && !going_down.read();) { + for (list::iterator iter = scheduled_stacks.begin(); iter != scheduled_stacks.end() && !going_down;) { lock.get_write(); RGWCoroutinesStack *stack = *iter; @@ -566,7 +567,7 @@ int RGWCoroutinesManager::run(list& stacks) if (ret < 0) { ldout(cct, 0) << "ERROR: failed to clone shard, completion_mgr.get_next() returned ret=" << ret << dendl; } - if (going_down.read() > 0) { + if (going_down) { ldout(cct, 5) << __func__ << "(): was stopped, exiting" << dendl; ret = -ECANCELED; canceled = true; @@ -585,7 +586,7 @@ int RGWCoroutinesManager::run(list& stacks) } lock.get_write(); - if (!context_stacks.empty() && !going_down.read()) { + if (!context_stacks.empty() && !going_down) { JSONFormatter formatter(true); formatter.open_array_section("context_stacks"); for (auto& s : context_stacks) { @@ -595,7 +596,7 @@ int RGWCoroutinesManager::run(list& stacks) lderr(cct) << __func__ << "(): ERROR: deadlock detected, dumping remaining coroutines:\n"; formatter.flush(*_dout); *_dout << dendl; - assert(context_stacks.empty() || going_down.read()); // assert on deadlock + assert(context_stacks.empty() || going_down); // assert on deadlock } for (auto stack : context_stacks) { diff --git a/src/rgw/rgw_coroutine.h b/src/rgw/rgw_coroutine.h index 821ff55889a..66afa74b375 100644 --- a/src/rgw/rgw_coroutine.h +++ b/src/rgw/rgw_coroutine.h @@ -22,6 +22,8 @@ #include "rgw_common.h" #include "rgw_boost_asio_coroutine.h" +#include + #define RGW_ASYNC_OPS_MGR_WINDOW 100 class RGWCoroutinesStack; @@ -39,7 +41,7 @@ class RGWCompletionManager : public RefCountedObject { SafeTimer timer; - atomic_t going_down; + std::atomic going_down = { false }; map waiters; @@ -506,9 +508,9 @@ public: class RGWCoroutinesManager { CephContext *cct; - atomic_t going_down; + std::atomic going_down = { false }; - atomic64_t run_context_count; + std::atomic run_context_count = { 0 }; map > run_contexts; RWLock lock; @@ -542,7 +544,8 @@ public: int run(list& ops); int run(RGWCoroutine *op); void stop() { - if (going_down.inc() == 1) { + bool expected = false; + if (going_down.compare_exchange_strong(expected, true)) { completion_mgr->go_down(); } } diff --git a/src/rgw/rgw_cr_rados.cc b/src/rgw/rgw_cr_rados.cc index 489ef589172..9316d620398 100644 --- a/src/rgw/rgw_cr_rados.cc +++ b/src/rgw/rgw_cr_rados.cc @@ -65,7 +65,7 @@ void RGWAsyncRadosProcessor::start() { } void RGWAsyncRadosProcessor::stop() { - going_down.set(1); + going_down = true; m_tp.drain(&req_wq); m_tp.stop(); for (auto iter = m_req_queue.begin(); iter != m_req_queue.end(); ++iter) { @@ -627,7 +627,7 @@ int RGWContinuousLeaseCR::operate() return set_cr_done(); } reenter(this) { - while (!going_down.read()) { + while (!going_down) { yield call(new RGWSimpleRadosLockCR(async_rados, store, obj, lock_name, cookie, interval)); caller->set_sleeping(false); /* will only be relevant when we return, that's why we can do it early */ diff --git a/src/rgw/rgw_cr_rados.h b/src/rgw/rgw_cr_rados.h index 8496201e0cd..ddc9524c8cd 100644 --- a/src/rgw/rgw_cr_rados.h +++ b/src/rgw/rgw_cr_rados.h @@ -6,6 +6,8 @@ #include "common/WorkQueue.h" #include "common/Throttle.h" +#include + class RGWAsyncRadosRequest : public RefCountedObject { RGWCoroutine *caller; RGWAioCompletionNotifier *notifier; @@ -57,7 +59,7 @@ public: class RGWAsyncRadosProcessor { deque m_req_queue; - atomic_t going_down; + std::atomic going_down = { false }; protected: RGWRados *store; ThreadPool m_tp; @@ -91,7 +93,7 @@ public: void queue(RGWAsyncRadosRequest *req); bool is_going_down() { - return (going_down.read() != 0); + return going_down; } }; @@ -1014,7 +1016,7 @@ class RGWContinuousLeaseCR : public RGWCoroutine { int interval; Mutex lock; - atomic_t going_down; + std::atomic going_down = { false }; bool locked{false}; RGWCoroutine *caller; @@ -1044,7 +1046,7 @@ public: } void go_down() { - going_down.set(1); + going_down = true; wakeup(); } diff --git a/src/rgw/rgw_file.cc b/src/rgw/rgw_file.cc index be3d356ec41..3fe8ba05591 100644 --- a/src/rgw/rgw_file.cc +++ b/src/rgw/rgw_file.cc @@ -27,6 +27,8 @@ #include "rgw_file.h" #include "rgw_lib_frontend.h" +#include + #define dout_subsys ceph_subsys_rgw using namespace rgw; @@ -37,7 +39,7 @@ namespace rgw { const string RGWFileHandle::root_name = "/"; - atomic RGWLibFS::fs_inst_counter; + std::atomic RGWLibFS::fs_inst_counter; uint32_t RGWLibFS::write_completion_interval_s = 10; diff --git a/src/rgw/rgw_file.h b/src/rgw/rgw_file.h index 5d964f9c2aa..cdb72b92f3e 100644 --- a/src/rgw/rgw_file.h +++ b/src/rgw/rgw_file.h @@ -745,7 +745,7 @@ namespace rgw { RGWUserInfo user; RGWAccessKey key; // XXXX acc_key - static atomic fs_inst_counter; + static std::atomic fs_inst_counter; static uint32_t write_completion_interval_s; std::string fsid; diff --git a/src/rgw/rgw_gc.cc b/src/rgw/rgw_gc.cc index c46f693daea..8fb461292dc 100644 --- a/src/rgw/rgw_gc.cc +++ b/src/rgw/rgw_gc.cc @@ -253,7 +253,7 @@ int RGWGC::process() bool RGWGC::going_down() { - return (down_flag.read() != 0); + return down_flag; } void RGWGC::start_processor() @@ -264,7 +264,7 @@ void RGWGC::start_processor() void RGWGC::stop_processor() { - down_flag.set(1); + down_flag = true; if (worker) { worker->stop(); worker->join(); diff --git a/src/rgw/rgw_gc.h b/src/rgw/rgw_gc.h index ca48a6e75e5..491796b50e8 100644 --- a/src/rgw/rgw_gc.h +++ b/src/rgw/rgw_gc.h @@ -6,7 +6,6 @@ #include "include/types.h" -#include "include/atomic.h" #include "include/rados/librados.hpp" #include "common/Mutex.h" #include "common/Cond.h" @@ -15,12 +14,14 @@ #include "rgw_rados.h" #include "cls/rgw/cls_rgw_types.h" +#include + class RGWGC { CephContext *cct; RGWRados *store; int max_objs; string *obj_names; - atomic_t down_flag; + std::atomic down_flag = { false }; int tag_index(const string& tag); diff --git a/src/rgw/rgw_http_client.cc b/src/rgw/rgw_http_client.cc index 070110e5099..81c4c6ef6bc 100644 --- a/src/rgw/rgw_http_client.cc +++ b/src/rgw/rgw_http_client.cc @@ -16,6 +16,8 @@ #include "rgw_coroutine.h" +#include + #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rgw @@ -24,7 +26,7 @@ struct rgw_http_req_data : public RefCountedObject { curl_slist *h; uint64_t id; int ret; - atomic_t done; + std::atomic done = { false }; RGWHTTPClient *client; void *user_info; bool registered; @@ -58,12 +60,12 @@ struct rgw_http_req_data : public RefCountedObject { easy_handle = NULL; h = NULL; - done.set(1); + done = true; cond.Signal(); } bool is_done() { - return done.read() != 0; + return done; } int get_retcode() { @@ -900,14 +902,14 @@ int RGWHTTPManager::set_threaded() void RGWHTTPManager::stop() { - if (is_stopped.read()) { + if (is_stopped) { return; } - is_stopped.set(1); + is_stopped = true; if (is_threaded) { - going_down.set(1); + going_down = true; signal_thread(); reqs_thread->join(); delete reqs_thread; @@ -935,7 +937,7 @@ void *RGWHTTPManager::reqs_thread_entry() ldout(cct, 20) << __func__ << ": start" << dendl; - while (!going_down.read()) { + while (!going_down) { int ret = do_curl_wait(cct, (CURLM *)multi_handle, thread_pipe[0]); if (ret < 0) { dout(0) << "ERROR: do_curl_wait() returned: " << ret << dendl; diff --git a/src/rgw/rgw_http_client.h b/src/rgw/rgw_http_client.h index 4266b7b50ba..cbe4f3d0312 100644 --- a/src/rgw/rgw_http_client.h +++ b/src/rgw/rgw_http_client.h @@ -6,10 +6,11 @@ #include "common/RWLock.h" #include "common/Cond.h" -#include "include/atomic.h" #include "rgw_common.h" #include "rgw_string.h" +#include + using param_pair_t = pair; using param_vec_t = vector; @@ -33,7 +34,7 @@ class RGWHTTPClient string last_url; bool verify_ssl; // Do not validate self signed certificates, default to false - atomic_t stopped; + std::atomic stopped { 0 }; protected: CephContext *cct; @@ -219,8 +220,8 @@ class RGWHTTPManager { RGWCompletionManager *completion_mgr; void *multi_handle; bool is_threaded; - atomic_t going_down; - atomic_t is_stopped; + std::atomic going_down { 0 }; + std::atomic is_stopped { 0 }; RWLock reqs_lock; map reqs; diff --git a/src/rgw/rgw_keystone.cc b/src/rgw/rgw_keystone.cc index 933308240e2..3294380ba10 100644 --- a/src/rgw/rgw_keystone.cc +++ b/src/rgw/rgw_keystone.cc @@ -613,7 +613,7 @@ int TokenCache::RevokeThread::check_revoked() bool TokenCache::going_down() const { - return (down_flag.read() != 0); + return down_flag; } void* TokenCache::RevokeThread::entry() diff --git a/src/rgw/rgw_keystone.h b/src/rgw/rgw_keystone.h index 5bacfb0da5e..df5650c5927 100644 --- a/src/rgw/rgw_keystone.h +++ b/src/rgw/rgw_keystone.h @@ -13,6 +13,8 @@ #include "rgw_http_client.h" #include "common/Cond.h" +#include + int rgw_open_cms_envelope(CephContext *cct, const std::string& src, std::string& dst); /* out */ @@ -216,7 +218,7 @@ class TokenCache { list::iterator lru_iter; }; - atomic_t down_flag; + std::atomic down_flag = { false }; class RevokeThread : public Thread { friend class TokenCache; @@ -271,7 +273,7 @@ class TokenCache { } ~TokenCache() { - down_flag.set(1); + down_flag = true; revocator.stop(); revocator.join(); diff --git a/src/rgw/rgw_lc.cc b/src/rgw/rgw_lc.cc index 61d4cc94427..38a66a35573 100644 --- a/src/rgw/rgw_lc.cc +++ b/src/rgw/rgw_lc.cc @@ -655,7 +655,7 @@ void RGWLC::start_processor() void RGWLC::stop_processor() { - down_flag.set(1); + down_flag = true; if (worker) { worker->stop(); worker->join(); @@ -672,7 +672,7 @@ void RGWLC::LCWorker::stop() bool RGWLC::going_down() { - return (down_flag.read() != 0); + return down_flag; } bool RGWLC::LCWorker::should_work(utime_t& now) diff --git a/src/rgw/rgw_lc.h b/src/rgw/rgw_lc.h index 61edd78aac7..e66735e3a2c 100644 --- a/src/rgw/rgw_lc.h +++ b/src/rgw/rgw_lc.h @@ -9,7 +9,6 @@ #include "common/debug.h" #include "include/types.h" -#include "include/atomic.h" #include "include/rados/librados.hpp" #include "common/Mutex.h" #include "common/Cond.h" @@ -19,6 +18,8 @@ #include "rgw_multi.h" #include "cls/rgw/cls_rgw_types.h" +#include + using namespace std; #define HASH_PRIME 7877 #define MAX_ID_LEN 255 @@ -227,7 +228,7 @@ class RGWLC { RGWRados *store; int max_objs; string *obj_names; - atomic_t down_flag; + std::atomic down_flag = { false }; string cookie; class LCWorker : public Thread { diff --git a/src/rgw/rgw_loadgen_process.cc b/src/rgw/rgw_loadgen_process.cc index 7f003facbb7..23e6fefca73 100644 --- a/src/rgw/rgw_loadgen_process.cc +++ b/src/rgw/rgw_loadgen_process.cc @@ -13,6 +13,8 @@ #include "rgw_loadgen.h" #include "rgw_client_io.h" +#include + #define dout_subsys ceph_subsys_rgw extern void signal_shutdown(); @@ -37,7 +39,7 @@ void RGWLoadGenProcess::run() vector buckets(num_buckets); - atomic_t failed; + std::atomic failed = { 0 }; for (i = 0; i < num_buckets; i++) { buckets[i] = "/loadgen"; @@ -51,7 +53,7 @@ void RGWLoadGenProcess::run() string *objs = new string[num_objs]; - if (failed.read()) { + if (failed) { derr << "ERROR: bucket creation failed" << dendl; goto done; } @@ -69,7 +71,7 @@ void RGWLoadGenProcess::run() checkpoint(); - if (failed.read()) { + if (failed) { derr << "ERROR: bucket creation failed" << dendl; goto done; } @@ -102,7 +104,7 @@ done: void RGWLoadGenProcess::gen_request(const string& method, const string& resource, - int content_length, atomic_t* fail_flag) + int content_length, std::atomic* fail_flag) { RGWLoadGenRequest* req = new RGWLoadGenRequest(store->get_new_req_id(), method, resource, @@ -138,7 +140,7 @@ void RGWLoadGenProcess::handle_request(RGWRequest* r) dout(20) << "process_request() returned " << ret << dendl; if (req->fail_flag) { - req->fail_flag->inc(); + req->fail_flag++; } } diff --git a/src/rgw/rgw_main.cc b/src/rgw/rgw_main.cc index 1bec56553a6..6ce71d78893 100644 --- a/src/rgw/rgw_main.cc +++ b/src/rgw/rgw_main.cc @@ -60,6 +60,7 @@ #include #include #include +#include #include "include/types.h" #include "common/BackTrace.h" @@ -77,11 +78,11 @@ static sig_t sighandler_alrm; class RGWProcess; static int signal_fd[2] = {0, 0}; -static atomic_t disable_signal_fd; +static std::atomic disable_signal_fd = { 0 }; void signal_shutdown() { - if (!disable_signal_fd.read()) { + if (!disable_signal_fd) { int val = 0; int ret = write(signal_fd[0], (char *)&val, sizeof(val)); if (ret < 0) { diff --git a/src/rgw/rgw_object_expirer_core.cc b/src/rgw/rgw_object_expirer_core.cc index 3bc033f0a68..fb0444186c9 100644 --- a/src/rgw/rgw_object_expirer_core.cc +++ b/src/rgw/rgw_object_expirer_core.cc @@ -230,7 +230,7 @@ bool RGWObjectExpirer::inspect_all_shards(const utime_t& last_run, bool RGWObjectExpirer::going_down() { - return (down_flag.read() != 0); + return down_flag; } void RGWObjectExpirer::start_processor() @@ -241,7 +241,7 @@ void RGWObjectExpirer::start_processor() void RGWObjectExpirer::stop_processor() { - down_flag.set(1); + down_flag = true; if (worker) { worker->stop(); worker->join(); diff --git a/src/rgw/rgw_object_expirer_core.h b/src/rgw/rgw_object_expirer_core.h index 83f0dd30754..6fe8d1410bf 100644 --- a/src/rgw/rgw_object_expirer_core.h +++ b/src/rgw/rgw_object_expirer_core.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "auth/Crypto.h" @@ -37,6 +38,8 @@ #include "rgw_usage.h" #include "rgw_replica_log.h" +#include + class RGWObjectExpirer { protected: RGWRados *store; @@ -65,7 +68,7 @@ protected: }; OEWorker *worker; - atomic_t down_flag; + std::atomic down_flag = { false }; public: explicit RGWObjectExpirer(RGWRados *_store) diff --git a/src/rgw/rgw_process.h b/src/rgw/rgw_process.h index 83c59a4cc37..005f2db6fef 100644 --- a/src/rgw/rgw_process.h +++ b/src/rgw/rgw_process.h @@ -17,6 +17,8 @@ #include "common/WorkQueue.h" #include "common/Throttle.h" +#include + #if !defined(dout_subsys) #define dout_subsys ceph_subsys_rgw #define def_dout_subsys @@ -182,7 +184,7 @@ public: void checkpoint(); void handle_request(RGWRequest* req) override; void gen_request(const string& method, const string& resource, - int content_length, atomic_t* fail_flag); + int content_length, std::atomic* fail_flag); void set_access_key(RGWAccessKey& key) { access_key = key; } }; diff --git a/src/rgw/rgw_quota.cc b/src/rgw/rgw_quota.cc index 02347ff743d..6a61400a110 100644 --- a/src/rgw/rgw_quota.cc +++ b/src/rgw/rgw_quota.cc @@ -26,6 +26,8 @@ #include "rgw_bucket.h" #include "rgw_user.h" +#include + #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rgw @@ -410,7 +412,7 @@ void UserAsyncRefreshHandler::handle_response(int r) } class RGWUserStatsCache : public RGWQuotaCache { - atomic_t down_flag; + std::atomic down_flag = { false }; RWLock rwlock; map modified_buckets; @@ -569,11 +571,11 @@ public: } bool going_down() { - return (down_flag.read() != 0); + return down_flag; } void stop() { - down_flag.set(1); + down_flag = true; rwlock.get_write(); stop_thread(&buckets_sync_thread); rwlock.unlock(); diff --git a/src/rgw/rgw_quota.h b/src/rgw/rgw_quota.h index d55dcaff952..9291434634c 100644 --- a/src/rgw/rgw_quota.h +++ b/src/rgw/rgw_quota.h @@ -15,11 +15,11 @@ #ifndef CEPH_RGW_QUOTA_H #define CEPH_RGW_QUOTA_H - #include "include/utime.h" -#include "include/atomic.h" #include "common/lru_map.h" +#include + static inline int64_t rgw_rounded_kb(int64_t bytes) { return (bytes + 1023) / 1024; diff --git a/src/rgw/rgw_rados.cc b/src/rgw/rgw_rados.cc index 329e09589ac..d6e9287a9c9 100644 --- a/src/rgw/rgw_rados.cc +++ b/src/rgw/rgw_rados.cc @@ -55,6 +55,7 @@ using namespace librados; #include #include #include +#include #include #include #include "auth/Crypto.h" // get_random_bytes() @@ -71,6 +72,8 @@ using namespace librados; #include "compressor/Compressor.h" +#include + #define dout_context g_ceph_context #define dout_subsys ceph_subsys_rgw @@ -2956,7 +2959,7 @@ protected: CephContext *cct; RGWRados *store; - atomic_t down_flag; + std::atomic down_flag = { false }; string thread_name; @@ -2972,7 +2975,8 @@ public: virtual int init() { return 0; } virtual int process() = 0; - bool going_down() { return down_flag.read() != 0; } + bool going_down() { return down_flag; } + void start(); void stop(); }; @@ -2985,7 +2989,7 @@ void RGWRadosThread::start() void RGWRadosThread::stop() { - down_flag.set(1); + down_flag = true; stop_process(); if (worker) { worker->stop(); @@ -5211,14 +5215,14 @@ int RGWRados::Bucket::List::list_objects(int max, vector * if (delim_pos >= 0) { string s = cur_marker.name.substr(0, delim_pos); s.append(bigger_than_delim); - cur_marker.set(s); + cur_marker = s; } } string skip_after_delim; while (truncated && count <= max) { if (skip_after_delim > cur_marker.name) { - cur_marker.set(skip_after_delim); + cur_marker = skip_after_delim; ldout(cct, 20) << "setting cur_marker=" << cur_marker.name << "[" << cur_marker.instance << "]" << dendl; } std::map ent_map; @@ -9789,8 +9793,8 @@ struct get_obj_data : public RefCountedObject { Mutex data_lock; list aio_data; RGWGetDataCB *client_cb; - atomic_t cancelled; - atomic_t err_code; + std::atomic cancelled = { false }; + std::atomic err_code = { 0 }; Throttle throttle; list read_list; @@ -9802,16 +9806,16 @@ struct get_obj_data : public RefCountedObject { throttle(cct, "get_obj_data", cct->_conf->rgw_get_obj_window_size, false) {} ~get_obj_data() override { } void set_cancelled(int r) { - cancelled.set(1); - err_code.set(r); + cancelled = true; + err_code = r; } bool is_cancelled() { - return cancelled.read() == 1; + return cancelled; } int get_err_code() { - return err_code.read(); + return err_code; } int wait_next_io(bool *done) { @@ -11655,7 +11659,7 @@ int RGWRados::pool_iterate(RGWPoolIterCtx& ctx, uint32_t num, vectorfilter(oid, oid)) continue; - e.key.set(oid); + e.key = oid; objs.push_back(e); } diff --git a/src/rgw/rgw_rados.h b/src/rgw/rgw_rados.h index c42256639d7..84abd068816 100644 --- a/src/rgw/rgw_rados.h +++ b/src/rgw/rgw_rados.h @@ -2199,7 +2199,7 @@ class RGWRados void get_bucket_instance_ids(const RGWBucketInfo& bucket_info, int shard_id, map *result); - atomic64_t max_req_id; + std::atomic max_req_id = { 0 }; Mutex lock; Mutex watchers_lock; SafeTimer *timer; @@ -2298,7 +2298,7 @@ protected: RGWPeriod current_period; public: - RGWRados() : max_req_id(0), lock("rados_timer_lock"), watchers_lock("watchers_lock"), timer(NULL), + RGWRados() : lock("rados_timer_lock"), watchers_lock("watchers_lock"), timer(NULL), gc(NULL), lc(NULL), obj_expirer(NULL), use_gc_thread(false), use_lc_thread(false), quota_threads(false), run_sync_thread(false), async_rados(nullptr), meta_notifier(NULL), data_notifier(NULL), meta_sync_processor_thread(NULL), @@ -2320,7 +2320,7 @@ public: meta_mgr(NULL), data_log(NULL) {} uint64_t get_new_req_id() { - return max_req_id.inc(); + return ++max_req_id; } librados::IoCtx* get_lc_pool_ctx() { diff --git a/src/rgw/rgw_request.h b/src/rgw/rgw_request.h index d9fc69bee1c..3c835f7b1c9 100644 --- a/src/rgw/rgw_request.h +++ b/src/rgw/rgw_request.h @@ -12,8 +12,11 @@ #if defined(WITH_RADOSGW_FCGI_FRONTEND) #include "rgw_fcgi.h" #endif + #include "common/QueueRing.h" +#include + struct RGWRequest { uint64_t id; @@ -56,10 +59,10 @@ struct RGWLoadGenRequest : public RGWRequest { string method; string resource; int content_length; - atomic_t* fail_flag; + std::atomic* fail_flag = nullptr; RGWLoadGenRequest(uint64_t req_id, const string& _m, const string& _r, int _cl, - atomic_t *ff) + std::atomic *ff) : RGWRequest(req_id), method(_m), resource(_r), content_length(_cl), fail_flag(ff) {} }; diff --git a/src/rgw/rgw_rest_conn.cc b/src/rgw/rgw_rest_conn.cc index 8699624002b..3cda4d305d6 100644 --- a/src/rgw/rgw_rest_conn.cc +++ b/src/rgw/rgw_rest_conn.cc @@ -26,7 +26,7 @@ int RGWRESTConn::get_url(string& endpoint) return -EIO; } - int i = counter.inc(); + int i = ++counter; endpoint = endpoints[i % endpoints.size()]; return 0; @@ -40,7 +40,7 @@ string RGWRESTConn::get_url() return endpoint; } - int i = counter.inc(); + int i = ++counter; endpoint = endpoints[i % endpoints.size()]; return endpoint; diff --git a/src/rgw/rgw_rest_conn.h b/src/rgw/rgw_rest_conn.h index 674387ffa05..2b2cf700ac4 100644 --- a/src/rgw/rgw_rest_conn.h +++ b/src/rgw/rgw_rest_conn.h @@ -9,6 +9,7 @@ #include "common/ceph_json.h" #include "common/RefCountedObj.h" +#include class CephContext; class RGWRados; @@ -55,7 +56,7 @@ class RGWRESTConn RGWAccessKey key; string self_zone_group; string remote_id; - atomic_t counter; + std::atomic counter = { 0 }; public: diff --git a/src/rgw/rgw_sync.cc b/src/rgw/rgw_sync.cc index 83c63bd1f82..94ead4aea29 100644 --- a/src/rgw/rgw_sync.cc +++ b/src/rgw/rgw_sync.cc @@ -52,7 +52,7 @@ RGWCoroutine *RGWSyncErrorLogger::log_error_cr(const string& source_zone, const ::encode(info, bl); store->time_log_prepare_entry(entry, real_clock::now(), section, name, bl); - uint32_t shard_id = counter.inc() % num_shards; + uint32_t shard_id = ++counter % num_shards; return new RGWRadosTimelogAddCR(store, oids[shard_id], entry); @@ -290,7 +290,7 @@ int RGWRemoteMetaLog::init() void RGWRemoteMetaLog::finish() { - going_down.set(1); + going_down = true; stop(); } @@ -1992,7 +1992,7 @@ int RGWRemoteMetaLog::run_sync() // get shard count and oldest log period from master rgw_mdlog_info mdlog_info; for (;;) { - if (going_down.read()) { + if (going_down) { ldout(store->ctx(), 1) << __func__ << "(): going down" << dendl; return 0; } @@ -2013,7 +2013,7 @@ int RGWRemoteMetaLog::run_sync() rgw_meta_sync_status sync_status; do { - if (going_down.read()) { + if (going_down) { ldout(store->ctx(), 1) << __func__ << "(): going down" << dendl; return 0; } @@ -2112,7 +2112,7 @@ int RGWRemoteMetaLog::run_sync() ldout(store->ctx(), 0) << "ERROR: bad sync state!" << dendl; return -EIO; } - } while (!going_down.read()); + } while (!going_down); return 0; } diff --git a/src/rgw/rgw_sync.h b/src/rgw/rgw_sync.h index bb245aedceb..40f15e10f64 100644 --- a/src/rgw/rgw_sync.h +++ b/src/rgw/rgw_sync.h @@ -8,6 +8,8 @@ #include "include/stringify.h" #include "common/RWLock.h" +#include + #define ERROR_LOGGER_SHARDS 32 #define RGW_SYNC_ERROR_LOG_SHARD_PREFIX "sync.error-log" @@ -65,7 +67,7 @@ class RGWSyncErrorLogger { vector oids; int num_shards; - atomic_t counter; + std::atomic counter = { 0 }; public: RGWSyncErrorLogger(RGWRados *_store, const string &oid_prefix, int _num_shards); RGWCoroutine *log_error_cr(const string& source_zone, const string& section, const string& name, uint32_t error_code, const string& message); @@ -195,7 +197,7 @@ class RGWRemoteMetaLog : public RGWCoroutinesManager { void init_sync_env(RGWMetaSyncEnv *env); int store_sync_info(const rgw_meta_sync_info& sync_info); - atomic_t going_down; + std::atomic going_down = { false }; public: RGWRemoteMetaLog(RGWRados *_store, RGWAsyncRadosProcessor *async_rados,