You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2022/12/21 19:09:51 UTC
[trafficserver] branch 10-Dev updated: std::atomic - replace use of core atomics in tsmemcache plugin. (#9269)
This is an automated email from the ASF dual-hosted git repository.
amc pushed a commit to branch 10-Dev
in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/10-Dev by this push:
new c8c6e7311 std::atomic - replace use of core atomics in tsmemcache plugin. (#9269)
c8c6e7311 is described below
commit c8c6e731101f9aa06c0ec0dfd292bc574a92d086
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Wed Dec 21 13:09:45 2022 -0600
std::atomic - replace use of core atomics in tsmemcache plugin. (#9269)
---
plugins/experimental/memcache/tsmemcache.cc | 7 +++----
plugins/experimental/memcache/tsmemcache.h | 8 +++++++-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/plugins/experimental/memcache/tsmemcache.cc b/plugins/experimental/memcache/tsmemcache.cc
index daabb181b..cb1b32f66 100644
--- a/plugins/experimental/memcache/tsmemcache.cc
+++ b/plugins/experimental/memcache/tsmemcache.cc
@@ -44,7 +44,6 @@ 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;
static void
tsmemcache_constants()
@@ -788,7 +787,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++;
if (f.set_append || f.set_prepend) {
header.nbytes = nbytes + rcache_header->nbytes;
} else {
@@ -935,7 +934,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++;
{
char *localdata = nullptr;
int len = 0;
@@ -1366,7 +1365,7 @@ MC::read_ascii_from_client_event(int event, void *data)
#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);
+ last_flush.exchange(new_last_flush);
#endif
if (!is_end_of_cmd(s, e)) {
break;
diff --git a/plugins/experimental/memcache/tsmemcache.h b/plugins/experimental/memcache/tsmemcache.h
index 7b0d5c341..69a78819b 100644
--- a/plugins/experimental/memcache/tsmemcache.h
+++ b/plugins/experimental/memcache/tsmemcache.h
@@ -21,6 +21,8 @@
limitations under the License.
*/
+#include <atomic>
+
#include "I_EventSystem.h"
#include "I_Net.h"
#include "I_Cache.h"
@@ -154,8 +156,12 @@ struct MC : Continuation {
uint64_t delta;
static int32_t verbosity;
+#if __WORDSIZE == 64
static ink_hrtime last_flush;
- static int64_t next_cas;
+#else
+ static std::atomic<ink_hrtime> last_flush;
+#endif
+ static inline std::atomic<int64_t> next_cas = 1;
int write_to_client(int64_t ntowrite = -1);
int write_then_read_from_client(int64_t ntowrite = -1);