Skip to content

Commit

Permalink
ceph: removes atomic_t; removes include/atomic.h
Browse files Browse the repository at this point in the history
Modifies source to use the standard library.

Signed-off-by: Jesse Williamson <jwilliamson@suse.de>
  • Loading branch information
Jesse Williamson committed Apr 13, 2017
1 parent 765bb07 commit 46e83e0
Show file tree
Hide file tree
Showing 148 changed files with 1,146 additions and 2,268 deletions.
9 changes: 5 additions & 4 deletions src/client/MetaRequest.h
Expand Up @@ -8,13 +8,14 @@
#include "include/types.h"
#include "include/xlist.h"
#include "include/filepath.h"
#include "include/atomic.h"
#include "mds/mdstypes.h"
#include "InodeRef.h"
#include "UserPerm.h"

#include "messages/MClientRequest.h"

#include <atomic>

class MClientReply;
class Dentry;
class dir_result_t;
Expand Down Expand Up @@ -48,7 +49,7 @@ struct MetaRequest {
__u32 sent_on_mseq; // mseq at last submission of this request
int num_fwd; // # of times i've been forwarded
int retry_attempt;
atomic_t ref;
std::atomic<unsigned> ref { 0 };

MClientReply *reply; // the reply
bool kick;
Expand Down Expand Up @@ -153,13 +154,13 @@ struct MetaRequest {
Dentry *old_dentry();

MetaRequest* get() {
ref.inc();
ref++;
return this;
}

/// psuedo-private put method; use Client::put_request()
bool _put() {
int v = ref.dec();
int v = --ref;
return v == 0;
}

Expand Down
4 changes: 3 additions & 1 deletion src/client/hypertable/CephBroker.cc
Expand Up @@ -39,9 +39,11 @@
#include <sys/uio.h>
#include <unistd.h>

#include <atomic>

using namespace Hypertable;

atomic_t CephBroker::ms_next_fd = ATOMIC_INIT(0);
std::atomic<unsigned> CephBroker::ms_next_fd = ATOMIC_VAR_INIT;

/* A thread-safe version of strerror */
static std::string cpp_strerror(int err)
Expand Down
2 changes: 1 addition & 1 deletion src/client/hypertable/CephBroker.h
Expand Up @@ -97,7 +97,7 @@ namespace Hypertable {

private:
struct ceph_mount_info *cmount;
static atomic_t ms_next_fd;
static std::atomic<unsigned> ms_next_fd { ATOMIC_VAR_INIT };

virtual void report_error(ResponseCallback *cb, int error);

Expand Down
4 changes: 4 additions & 0 deletions src/common/Finisher.cc
Expand Up @@ -5,6 +5,10 @@
#include "Finisher.h"

#include "common/debug.h"

// reinclude our assert to clobber the system one
#include "include/assert.h"

#define dout_subsys ceph_subsys_finisher
#undef dout_prefix
#define dout_prefix *_dout << "finisher(" << this << ") "
Expand Down
3 changes: 2 additions & 1 deletion src/common/Finisher.h
Expand Up @@ -15,12 +15,13 @@
#ifndef CEPH_FINISHER_H
#define CEPH_FINISHER_H

#include "include/atomic.h"
#include "common/Mutex.h"
#include "common/Cond.h"
#include "common/Thread.h"
#include "common/perf_counters.h"

#include <atomic>

class CephContext;

/// Finisher queue length performance counter ID.
Expand Down
22 changes: 11 additions & 11 deletions src/common/HeartbeatMap.cc
Expand Up @@ -76,13 +76,13 @@ bool HeartbeatMap::_check(const heartbeat_handle_d *h, const char *who, time_t n
bool healthy = true;
time_t was;

was = h->timeout.read();
was = h->timeout.load();
if (was && was < now) {
ldout(m_cct, 1) << who << " '" << h->name << "'"
<< " had timed out after " << h->grace << dendl;
healthy = false;
}
was = h->suicide_timeout.read();
was = h->suicide_timeout.load();
if (was && was < now) {
ldout(m_cct, 1) << who << " '" << h->name << "'"
<< " had suicide timed out after " << h->suicide_grace << dendl;
Expand All @@ -100,13 +100,13 @@ void HeartbeatMap::reset_timeout(heartbeat_handle_d *h, time_t grace, time_t sui
time_t now = time(NULL);
_check(h, "reset_timeout", now);

h->timeout.set(now + grace);
h->timeout = now + grace;
h->grace = grace;

if (suicide_grace)
h->suicide_timeout.set(now + suicide_grace);
h->suicide_timeout = now + suicide_grace;
else
h->suicide_timeout.set(0);
h->suicide_timeout = 0;
h->suicide_grace = suicide_grace;
}

Expand All @@ -115,8 +115,8 @@ void HeartbeatMap::clear_timeout(heartbeat_handle_d *h)
ldout(m_cct, 20) << "clear_timeout '" << h->name << "'" << dendl;
time_t now = time(NULL);
_check(h, "clear_timeout", now);
h->timeout.set(0);
h->suicide_timeout.set(0);
h->timeout = 0;
h->suicide_timeout = 0;
}

bool HeartbeatMap::is_healthy()
Expand Down Expand Up @@ -149,8 +149,8 @@ bool HeartbeatMap::is_healthy()
}
m_rwlock.put_read();

m_unhealthy_workers.set(unhealthy);
m_total_workers.set(total);
m_unhealthy_workers = unhealthy;
m_total_workers = total;

ldout(m_cct, 20) << "is_healthy = " << (healthy ? "healthy" : "NOT HEALTHY")
<< ", total workers: " << total << ", number of unhealthy: " << unhealthy << dendl;
Expand All @@ -159,12 +159,12 @@ bool HeartbeatMap::is_healthy()

int HeartbeatMap::get_unhealthy_workers() const
{
return m_unhealthy_workers.read();
return m_unhealthy_workers.load();
}

int HeartbeatMap::get_total_workers() const
{
return m_total_workers.read();
return m_total_workers.load();
}

void HeartbeatMap::check_touch_file()
Expand Down
9 changes: 4 additions & 5 deletions src/common/HeartbeatMap.h
Expand Up @@ -17,12 +17,11 @@

#include <pthread.h>

#include <atomic>
#include <string>
#include <list>
#include <time.h>

#include "include/atomic.h"

#include "RWLock.h"

class CephContext;
Expand All @@ -43,7 +42,7 @@ namespace ceph {
struct heartbeat_handle_d {
const std::string name;
pthread_t thread_id;
atomic_t timeout, suicide_timeout;
std::atomic<unsigned> timeout { 0 }, suicide_timeout { 0 };
time_t grace, suicide_grace;
std::list<heartbeat_handle_d*>::iterator list_item;

Expand Down Expand Up @@ -83,8 +82,8 @@ class HeartbeatMap {
RWLock m_rwlock;
time_t m_inject_unhealthy_until;
std::list<heartbeat_handle_d*> m_workers;
atomic_t m_unhealthy_workers;
atomic_t m_total_workers;
std::atomic<unsigned> m_unhealthy_workers { 0 };
std::atomic<unsigned> m_total_workers { 0 };

bool _check(const heartbeat_handle_d *h, const char *who, time_t now);
};
Expand Down
2 changes: 1 addition & 1 deletion src/common/LogClient.h
Expand Up @@ -248,7 +248,7 @@ class LogClient
bool is_mon;
Mutex log_lock;
version_t last_log_sent;
std::atomic<uint64_t> last_log;
std::atomic<uint64_t> last_log { 0 };
std::deque<LogEntry> log_queue;

std::map<std::string, LogChannelRef> channels;
Expand Down
8 changes: 6 additions & 2 deletions src/common/OutputDataSocket.cc
Expand Up @@ -34,19 +34,23 @@
#include <stdint.h>
#include <string.h>
#include <string>
#include <atomic>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <unistd.h>

#include "include/compat.h"

using std::ostringstream;

// re-include our assert to clobber the system one
#include "include/assert.h"

#define dout_subsys ceph_subsys_asok
#undef dout_prefix
#define dout_prefix *_dout << "asok(" << (void*)m_cct << ") "

using std::ostringstream;

/*
* UNIX domain sockets created by an application persist even after that
* application closes, unless they're explicitly unlinked. This is because the
Expand Down
10 changes: 6 additions & 4 deletions src/common/QueueRing.h
Expand Up @@ -3,6 +3,8 @@

#include <list>
#include <vector>
#include <atomic>

#include "common/Mutex.h"
#include "common/Cond.h"

Expand Down Expand Up @@ -43,18 +45,18 @@ class QueueRing {

std::vector<QueueBucket> buckets;
int num_buckets;
atomic_t cur_read_bucket;
atomic_t cur_write_bucket;
std::atomic<unsigned> cur_read_bucket { 0 };
std::atomic<unsigned> cur_write_bucket { 0 };
public:
QueueRing(int n) : buckets(n), num_buckets(n) {
}

void enqueue(const T& entry) {
buckets[cur_write_bucket.inc() % num_buckets].enqueue(entry);
buckets[++cur_write_bucket % num_buckets].enqueue(entry);
};

void dequeue(T *entry) {
buckets[cur_read_bucket.inc() % num_buckets].dequeue(entry);
buckets[++cur_read_bucket % num_buckets].dequeue(entry);
}
};

Expand Down
27 changes: 15 additions & 12 deletions src/common/RWLock.h
Expand Up @@ -18,18 +18,21 @@
#define CEPH_RWLock_Posix__H

#include <pthread.h>

#include <atomic>
#include <string>

#include <include/assert.h>

#include "lockdep.h"
#include "include/atomic.h"
#include "common/valgrind.h"

class RWLock final
{
mutable pthread_rwlock_t L;
std::string name;
mutable int id;
mutable atomic_t nrlock, nwlock;
mutable std::atomic<unsigned> nrlock { 0 }, nwlock { 0 };
bool track, lockdep;

std::string unique_name(const char* name) const;
Expand Down Expand Up @@ -65,12 +68,12 @@ class RWLock final

bool is_locked() const {
assert(track);
return (nrlock.read() > 0) || (nwlock.read() > 0);
return (nrlock.load() > 0) || (nwlock.load() > 0);
}

bool is_wlocked() const {
assert(track);
return (nwlock.read() > 0);
return (nwlock.load() > 0);
}
~RWLock() {
// The following check is racy but we are about to destroy
Expand All @@ -85,11 +88,11 @@ class RWLock final

void unlock(bool lockdep=true) const {
if (track) {
if (nwlock.read() > 0) {
nwlock.dec();
if (nwlock.load() > 0) {
nwlock--;
} else {
assert(nrlock.read() > 0);
nrlock.dec();
assert(nrlock.load() > 0);
nrlock--;
}
}
if (lockdep && this->lockdep && g_lockdep)
Expand All @@ -105,12 +108,12 @@ class RWLock final
assert(r == 0);
if (lockdep && g_lockdep) id = lockdep_locked(name.c_str(), id);
if (track)
nrlock.inc();
nrlock++;
}
bool try_get_read() const {
if (pthread_rwlock_tryrdlock(&L) == 0) {
if (track)
nrlock.inc();
nrlock++;
if (lockdep && g_lockdep) id = lockdep_locked(name.c_str(), id);
return true;
}
Expand All @@ -129,15 +132,15 @@ class RWLock final
if (lockdep && this->lockdep && g_lockdep)
id = lockdep_locked(name.c_str(), id);
if (track)
nwlock.inc();
nwlock++;

}
bool try_get_write(bool lockdep=true) {
if (pthread_rwlock_trywrlock(&L) == 0) {
if (lockdep && this->lockdep && g_lockdep)
id = lockdep_locked(name.c_str(), id);
if (track)
nwlock.inc();
nwlock++;
return true;
}
return false;
Expand Down

0 comments on commit 46e83e0

Please sign in to comment.