You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by bc...@apache.org on 2018/10/10 23:22:07 UTC
[trafficserver] branch 8.0.x updated: Cache: update internal
counters to be std::atomic.
This is an automated email from the ASF dual-hosted git repository.
bcall pushed a commit to branch 8.0.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/8.0.x by this push:
new 1cf3cae Cache: update internal counters to be std::atomic.
1cf3cae is described below
commit 1cf3cae98db96c181066816eff328ab4c217271c
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Mon Oct 8 12:35:54 2018 -0500
Cache: update internal counters to be std::atomic.
(cherry picked from commit 4191f92371afffb213f194137fcdd1b0d18763e6)
---
iocore/cache/Cache.cc | 23 +++++++++++++----------
iocore/cache/CacheHosting.cc | 1 -
iocore/cache/CachePagesInternal.cc | 1 -
iocore/cache/P_CacheVol.h | 4 +++-
4 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/iocore/cache/Cache.cc b/iocore/cache/Cache.cc
index 64bb1e6..2bac39c 100644
--- a/iocore/cache/Cache.cc
+++ b/iocore/cache/Cache.cc
@@ -37,6 +37,8 @@
#include "tscore/hugepages.h"
+#include <atomic>
+
const VersionNumber CACHE_DB_VERSION(CACHE_DB_MAJOR_VERSION, CACHE_DB_MINOR_VERSION);
// Compilation Options
@@ -87,11 +89,11 @@ int cache_config_compatibility_4_2_0_fixup = 1;
// Globals
-RecRawStatBlock *cache_rsb = nullptr;
-Cache *theCache = nullptr;
-CacheDisk **gdisks = nullptr;
-int gndisks = 0;
-static int initialize_disk;
+RecRawStatBlock *cache_rsb = nullptr;
+Cache *theCache = nullptr;
+CacheDisk **gdisks = nullptr;
+int gndisks = 0;
+std::atomic<int> initialize_disk = 0;
Cache *caches[NUM_CACHE_FRAG_TYPES] = {nullptr};
CacheSync *cacheDirSync = nullptr;
Store theCacheStore;
@@ -104,8 +106,8 @@ bool CacheProcessor::check = false;
int CacheProcessor::start_internal_flags = 0;
int CacheProcessor::auto_clear_flag = 0;
CacheProcessor cacheProcessor;
-Vol **gvol = nullptr;
-int gnvol = 0;
+Vol **gvol = nullptr;
+std::atomic<int> gnvol = 0;
ClassAllocator<CacheVC> cacheVConnectionAllocator("cacheVConnection");
ClassAllocator<EvacuationBlock> evacuationBlockAllocator("evacuationBlock");
ClassAllocator<CacheRemoveCont> cacheRemoveContAllocator("cacheRemoveCont");
@@ -749,7 +751,7 @@ CacheProcessor::start_internal(int flags)
void
CacheProcessor::diskInitialized()
{
- int n_init = ink_atomic_increment(&initialize_disk, 1);
+ int n_init = initialize_disk++;
int bad_disks = 0;
int res = 0;
int i;
@@ -906,7 +908,8 @@ CacheProcessor::cacheInitialized()
}
if (caches_ready) {
- Debug("cache_init", "CacheProcessor::cacheInitialized - caches_ready=0x%0X, gnvol=%d", (unsigned int)caches_ready, gnvol);
+ Debug("cache_init", "CacheProcessor::cacheInitialized - caches_ready=0x%0X, gnvol=%d", (unsigned int)caches_ready,
+ gnvol.load());
int64_t ram_cache_bytes = 0;
@@ -1764,7 +1767,7 @@ Vol::dir_init_done(int /* event ATS_UNUSED */, void * /* data ATS_UNUSED */)
eventProcessor.schedule_in(this, HRTIME_MSECONDS(5), ET_CALL);
return EVENT_CONT;
} else {
- int vol_no = ink_atomic_increment(&gnvol, 1);
+ int vol_no = gnvol++;
ink_assert(!gvol[vol_no]);
gvol[vol_no] = this;
SET_HANDLER(&Vol::aggWrite);
diff --git a/iocore/cache/CacheHosting.cc b/iocore/cache/CacheHosting.cc
index 292d0a5..e7895b3 100644
--- a/iocore/cache/CacheHosting.cc
+++ b/iocore/cache/CacheHosting.cc
@@ -772,7 +772,6 @@ extern CacheDisk **gdisks;
extern Queue<CacheVol> cp_list;
extern int cp_list_len;
extern ConfigVolumes config_volumes;
-extern int gnvol;
extern void cplist_init();
extern int cplist_reconfigure();
diff --git a/iocore/cache/CachePagesInternal.cc b/iocore/cache/CachePagesInternal.cc
index 3799621..c67483b 100644
--- a/iocore/cache/CachePagesInternal.cc
+++ b/iocore/cache/CachePagesInternal.cc
@@ -52,7 +52,6 @@ extern ShowCacheInternal *theshowcacheInternal;
Action *register_ShowCacheInternal(Continuation *c, HTTPHdr *h);
extern Vol **gvol;
-extern int gnvol;
// Stat Pages
ShowCacheInternal *theshowcacheInternal = nullptr;
diff --git a/iocore/cache/P_CacheVol.h b/iocore/cache/P_CacheVol.h
index 2f0d2db..a59df2c 100644
--- a/iocore/cache/P_CacheVol.h
+++ b/iocore/cache/P_CacheVol.h
@@ -23,6 +23,8 @@
#pragma once
+#include <atomic>
+
#define CACHE_BLOCK_SHIFT 9
#define CACHE_BLOCK_SIZE (1 << CACHE_BLOCK_SHIFT) // 512, smallest sector size
#define ROUND_TO_STORE_BLOCK(_x) INK_ALIGN((_x), STORE_BLOCK_SIZE)
@@ -328,7 +330,7 @@ struct Doc {
// Global Data
extern Vol **gvol;
-extern int gnvol;
+extern std::atomic<int> gnvol;
extern ClassAllocator<OpenDirEntry> openDirEntryAllocator;
extern ClassAllocator<EvacuationBlock> evacuationBlockAllocator;
extern ClassAllocator<EvacuationKey> evacuationKeyAllocator;