Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/traffic_manager/traffic_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static void SignalHandler(int sig);
static void SignalAlrmHandler(int sig);
#endif

static std::atomic<int> sigHupNotifier;
static std::atomic<int> sigHupNotifier{0};
static void SigChldHandler(int sig);

static void
Expand Down
6 changes: 3 additions & 3 deletions example/remap/remap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ TSRemapDeleteInstance(void *ih)
delete ri;
}

static std::atomic<uint64_t> processing_counter; // sequential counter
static int arg_index;
static std::atomic<uint64_t> processing_counter{0}; // sequential counter
static int arg_index = 0;

/* -------------------------- TSRemapDoRemap -------------------------------- */
TSRemapStatus
Expand All @@ -223,7 +223,7 @@ TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
const char *temp2;
int len, len2, port;
TSMLoc cfield;
uint64_t _processing_counter = processing_counter++;
uint64_t _processing_counter = processing_counter.fetch_add(1) + 1;

remap_entry *ri = (remap_entry *)ih;
TSDebug(PLUGIN_NAME, "enter");
Expand Down
12 changes: 6 additions & 6 deletions iocore/cache/Cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ int cache_config_compatibility_4_2_0_fixup = 1;

// Globals

RecRawStatBlock *cache_rsb = nullptr;
Cache *theStreamCache = nullptr;
Cache *theCache = nullptr;
CacheDisk **gdisks = nullptr;
int gndisks = 0;
static int initialize_disk;
RecRawStatBlock *cache_rsb = nullptr;
Cache *theStreamCache = nullptr;
Cache *theCache = nullptr;
CacheDisk **gdisks = nullptr;
int gndisks = 0;
static int initialize_disk = 0;
Cache *caches[NUM_CACHE_FRAG_TYPES] = {nullptr};
CacheSync *cacheDirSync = nullptr;
Store theCacheStore;
Expand Down
1 change: 1 addition & 0 deletions iocore/eventsystem/P_UnixEventProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#define _P_UnixEventProcessor_h_

#include "ts/ink_align.h"
#include "ts/ink_atomic.h"
#include "I_EventProcessor.h"

const int LOAD_BALANCE_INTERVAL = 1;
Expand Down
1 change: 1 addition & 0 deletions iocore/eventsystem/test_Event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "I_EventSystem.h"
#include "ts/I_Layout.h"
#include "ts/ink_atomic.h"

#include "diags.i"

Expand Down
12 changes: 6 additions & 6 deletions lib/ts/Ptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef PTR_H_FBBD7DC3_CA5D_4715_9162_5E4DDA93353F
#define PTR_H_FBBD7DC3_CA5D_4715_9162_5E4DDA93353F

#include "ts/ink_atomic.h"
#include <atomic>

////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -64,14 +64,14 @@ class RefCountObj : public ForceVFPTToTop
int
refcount_inc()
{
return ink_atomic_increment((int *)&m_refcount, 1) + 1;
return m_refcount.fetch_add(1) + 1;
}

// Decrement the reference count, returning the new count.
int
refcount_dec()
{
return ink_atomic_increment((int *)&m_refcount, -1) - 1;
return m_refcount.fetch_sub(1) - 1;
}

int
Expand All @@ -87,7 +87,7 @@ class RefCountObj : public ForceVFPTToTop
}

private:
int m_refcount;
std::atomic<int> m_refcount;
};

#define REF_COUNT_OBJ_REFCOUNT_INC(_x) (_x)->refcount_inc()
Expand Down Expand Up @@ -164,7 +164,7 @@ template <class T> class Ptr
detach()
{
T *tmp = m_ptr;
m_ptr = NULL;
m_ptr = nullptr;
return tmp;
}

Expand Down Expand Up @@ -246,7 +246,7 @@ Ptr<T>::clear()
if (m_ptr) {
if (!m_ptr->refcount_dec())
m_ptr->free();
m_ptr = NULL;
m_ptr = nullptr;
}
}

Expand Down
4 changes: 2 additions & 2 deletions mgmt/ProcessManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ ProcessManager::start(std::function<void()> const &cb)
init = cb;

ink_release_assert(running == 0);
ink_atomic_increment(&running, 1);
running.fetch_add(1);
poll_thread = ink_thread_create(processManagerThread, nullptr, 0, 0, nullptr);
}

Expand All @@ -109,7 +109,7 @@ ProcessManager::stop()
Debug("pmgmt", "stopping process manager");

ink_release_assert(running == 1);
ink_atomic_decrement(&running, 1);
running.fetch_sub(1);

int tmp = local_manager_sockfd;

Expand Down
3 changes: 2 additions & 1 deletion mgmt/ProcessManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "ts/ink_sock.h"

#include "ts/ink_apidefs.h"
#include <atomic>
#include <functional>

class ConfigUpdateCbTable;
Expand Down Expand Up @@ -84,7 +85,7 @@ class ProcessManager : public BaseManager
pid_t pid;

ink_thread poll_thread = ink_thread_null();
int running = 0;
std::atomic<int> running{0};

/// Thread initialization callback.
/// This allows @c traffic_server and @c traffic_manager to perform different initialization in the thread.
Expand Down
12 changes: 6 additions & 6 deletions mgmt/ProxyConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ ConfigProcessor::set(unsigned int id, ConfigInfo *info, unsigned timeout_secs)
int idx;

if (id == 0) {
id = ink_atomic_increment((int *)&ninfos, 1) + 1;
id = ninfos.fetch_add(1) + 1;
ink_assert(id != 0);
ink_assert(id <= MAX_CONFIGS);
}
Expand All @@ -147,7 +147,7 @@ ConfigProcessor::set(unsigned int id, ConfigInfo *info, unsigned timeout_secs)
}

idx = id - 1;
old_info = ink_atomic_swap(&infos[idx], info);
old_info = (infos[idx]).exchange(info);

Debug("config", "Set for slot %d 0x%" PRId64 " was 0x%" PRId64 " with ref count %d", id, (int64_t)info, (int64_t)old_info,
(old_info) ? old_info->refcount() : 0);
Expand Down Expand Up @@ -214,7 +214,7 @@ enum {
};

struct RegressionConfig : public ConfigInfo {
static int nobjects; // count of outstanding RegressionConfig objects (not-reentrant)
static std::atomic<int> nobjects; // count of outstanding RegressionConfig objects (not-reentrant)

// DeferredCall is a simple function call wrapper that defers itself until the RegressionConfig
// object count drops below the specified count.
Expand Down Expand Up @@ -251,7 +251,7 @@ struct RegressionConfig : public ConfigInfo {
box.check(this->refcount() == 1, "invalid refcount %d (should be 1)", this->refcount());
}

ink_atomic_increment(&nobjects, 1);
nobjects.fetch_add(1);
}

~RegressionConfig() override
Expand All @@ -268,15 +268,15 @@ struct RegressionConfig : public ConfigInfo {
box.check(*this->pstatus == REGRESSION_TEST_INPROGRESS, "intermediate config out of sequence, *pstatus is %d", *pstatus);
}

ink_atomic_increment(&nobjects, -1);
nobjects.fetch_sub(1);
}

RegressionTest *test;
int *pstatus;
unsigned flags;
};

int RegressionConfig::nobjects = 0;
std::atomic<int> RegressionConfig::nobjects{0};

struct ProxyConfig_Set_Completion {
ProxyConfig_Set_Completion(int _id, RegressionConfig *_c) : configid(_id), config(_c) {}
Expand Down
4 changes: 2 additions & 2 deletions mgmt/ProxyConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class ConfigProcessor
void release(unsigned int id, ConfigInfo *data);

public:
ConfigInfo *infos[MAX_CONFIGS];
int ninfos;
std::atomic<ConfigInfo *> infos[MAX_CONFIGS];
std::atomic<int> ninfos;
};

// A Continuation wrapper that calls the static reconfigure() method of the given class.
Expand Down
15 changes: 9 additions & 6 deletions plugins/background_fetch/configs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
#ifndef CONFIGS_H_DEBFCE23_D6E9_40C2_AAA5_32B32586A3DA
#define CONFIGS_H_DEBFCE23_D6E9_40C2_AAA5_32B32586A3DA

#include <stdlib.h>
#include <atomic>
#include <cinttypes>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include "rules.h"
#include "ts/ink_atomic.h"

// Constants
const char PLUGIN_NAME[] = "background_fetch";
Expand All @@ -43,14 +46,14 @@ class BgFetchConfig
void
acquire()
{
ink_atomic_increment(&_ref_count, 1);
_ref_count.fetch_add(1);
}

void
release()
{
TSDebug(PLUGIN_NAME, "ref_count is %d", _ref_count);
if (1 >= ink_atomic_decrement(&_ref_count, 1)) {
TSDebug(PLUGIN_NAME, "ref_count is %d", (int)_ref_count);
if (1 >= _ref_count.fetch_sub(1)) {
TSDebug(PLUGIN_NAME, "configuration deleted, due to ref-counting");
delete this;
}
Expand Down Expand Up @@ -82,7 +85,7 @@ class BgFetchConfig

TSCont _cont;
BgFetchRule *_rules;
int _ref_count;
std::atomic<int> _ref_count;
};

#endif /* CONFIGS_H_DEBFCE23_D6E9_40C2_AAA5_32B32586A3DA */
1 change: 0 additions & 1 deletion plugins/experimental/geoip_acl/lulu.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include <sys/types.h>

#include "ts/ink_defs.h"
#include "ts/ink_atomic.h"

// Used for Debug etc.
static const char *PLUGIN_NAME = "geoip_acl";
Expand Down
22 changes: 9 additions & 13 deletions plugins/experimental/memcache/tsmemcache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ ClassAllocator<MC> theMCAllocator("MC");
static time_t base_day_time;

// These should be persistent.
int32_t MC::verbosity = 0;
ink_hrtime MC::last_flush = 0;
int64_t MC::next_cas = 1;
int32_t MC::verbosity = 0;
std::atomic<ink_hrtime> MC::last_flush{0};
std::atomic<int64_t> MC::next_cas{1};

static void
tsmemcache_constants()
Expand Down Expand Up @@ -444,7 +444,7 @@ MC::cache_read_event(int event, void *data)
}
{
ink_hrtime t = Thread::get_hrtime();
if (((ink_hrtime)rcache_header->settime) <= last_flush ||
if (((ink_hrtime)rcache_header->settime) <= last_flush.load() ||
t >= ((ink_hrtime)rcache_header->settime) + HRTIME_SECONDS(rcache_header->exptime)) {
goto Lfail;
}
Expand Down Expand Up @@ -777,7 +777,7 @@ MC::ascii_set_event(int event, void *data)
goto Lfail;
}
ink_hrtime t = Thread::get_hrtime();
if (((ink_hrtime)wcache_header->settime) <= last_flush ||
if (((ink_hrtime)wcache_header->settime) <= last_flush.load() ||
t >= ((ink_hrtime)wcache_header->settime) + HRTIME_SECONDS(wcache_header->exptime)) {
goto Lstale;
}
Expand Down Expand Up @@ -813,7 +813,7 @@ MC::ascii_set_event(int event, void *data)
return ASCII_RESPONSE("EXISTS");
}
}
header.cas = ink_atomic_increment(&next_cas, 1);
header.cas = next_cas.fetch_add(1);
if (f.set_append || f.set_prepend) {
header.nbytes = nbytes + rcache_header->nbytes;
} else {
Expand Down Expand Up @@ -937,7 +937,7 @@ MC::ascii_incr_decr_event(int event, void *data)
goto Lfail;
}
ink_hrtime t = Thread::get_hrtime();
if (((ink_hrtime)wcache_header->settime) <= last_flush ||
if (((ink_hrtime)wcache_header->settime) <= last_flush.load() ||
t >= ((ink_hrtime)wcache_header->settime) + HRTIME_SECONDS(wcache_header->exptime)) {
goto Lfail;
}
Expand All @@ -960,7 +960,7 @@ MC::ascii_incr_decr_event(int event, void *data)
header.exptime = UINT32_MAX; // 136 years
}
}
header.cas = ink_atomic_increment(&next_cas, 1);
header.cas = next_cas.fetch_add(1);
{
char *data = 0;
int len = 0;
Expand Down Expand Up @@ -1385,11 +1385,7 @@ MC::read_ascii_from_client_event(int event, void *data)
}
f.noreply = is_noreply(&s, e);
ink_hrtime new_last_flush = Thread::get_hrtime() + HRTIME_SECONDS(time_offset);
#if __WORDSIZE == 64
last_flush = new_last_flush; // this will be atomic for native word size
#else
ink_atomic_swap(&last_flush, new_last_flush);
#endif
last_flush.store(new_last_flush);
if (!is_end_of_cmd(s, e)) {
break;
}
Expand Down
6 changes: 4 additions & 2 deletions plugins/experimental/memcache/tsmemcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#ifndef tsmemcache_h
#define tsmemcache_h

#include <atomic>

#include "I_EventSystem.h"
#include "I_Net.h"
#include "I_Cache.h"
Expand Down Expand Up @@ -155,8 +157,8 @@ struct MC : Continuation {
uint64_t delta;

static int32_t verbosity;
static ink_hrtime last_flush;
static int64_t next_cas;
static std::atomic<ink_hrtime> last_flush;
static std::atomic<int64_t> next_cas;

int write_to_client(int64_t ntowrite = -1);
int write_then_read_from_client(int64_t ntowrite = -1);
Expand Down
8 changes: 4 additions & 4 deletions plugins/gzip/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
#ifndef GZIP_CONFIGURATION_H_
#define GZIP_CONFIGURATION_H_

#include <atomic>
#include <string>
#include <vector>
#include "debug_macros.h"
#include "ts/ink_atomic.h"

namespace Gzip
{
Expand Down Expand Up @@ -123,12 +123,12 @@ class HostConfiguration
void
hold()
{
ink_atomic_increment(&ref_count_, 1);
ref_count_++;
}
void
release()
{
if (1 >= ink_atomic_decrement(&ref_count_, 1)) {
if (1 >= ref_count_--) {
debug("released and deleting HostConfiguration for %s settings", host_.size() > 0 ? host_.c_str() : "global");
delete this;
}
Expand All @@ -141,7 +141,7 @@ class HostConfiguration
bool remove_accept_encoding_;
bool flush_;
int compression_algorithms_;
int ref_count_;
std::atomic<int> ref_count_;

StringContainer compressible_content_types_;
StringContainer disallows_;
Expand Down
Loading