ywkaras commented on code in PR #9394:
URL: https://github.com/apache/trafficserver/pull/9394#discussion_r1111116672


##########
include/tscpp/util/Bravo.h:
##########
@@ -0,0 +1,382 @@
+/** @file
+
+  Implementation of BRAVO - Biased Locking for Reader-Writer Locks
+
+  Dave Dice and Alex Kogan. 2019. BRAVO: Biased Locking for Reader-Writer 
Locks.
+  In Proceedings of the 2019 USENIX Annual Technical Conference (ATC). USENIX 
Association, Renton, WA, 315–328.
+
+  https://www.usenix.org/conference/atc19/presentation/dice
+
+  > Section 3.
+  >   BRAVO acts as an accelerator layer, as readers can always fall back to 
the traditional underlying lock to gain read access.
+  >   ...
+  >   Write performance and the scalability of read-vs-write and 
write-vs-write behavior depends solely on the underlying lock.
+
+  This code is C++ version of puzpuzpuz/xsync's RBMutex
+  https://github.com/puzpuzpuz/xsync/blob/main/rbmutex.go
+  Copyright (c) 2021 Andrey Pechkurov
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#pragma once
+
+#include <array>
+#include <atomic>
+#include <cassert>
+#include <chrono>
+#include <shared_mutex>
+#include <thread>
+
+namespace ts::bravo
+{
+static inline uint32_t
+mix32(uint64_t z)
+{
+  z = (z ^ (z >> 33)) * 0xff51afd7ed558ccdL;
+  z = (z ^ (z >> 33)) * 0xc4ceb9fe1a85ec53L;
+  return static_cast<uint32_t>(z >> 32);
+}
+
+using time_point = std::chrono::time_point<std::chrono::system_clock>;
+
+#ifdef __cpp_lib_hardware_interference_size
+using std::hardware_constructive_interference_size;

Review Comment:
   It seems like this constant is only available in newer versions of gcc and 
clang.  We could maybe get the cache line size out of /proc/cpuinfo when the 
target is Linux?
   ```
   wkaras ~
   $ grep -e cache_alignment -e processor /proc/cpuinfo | head -n 4
   processor    : 0
   cache_alignment      : 64
   processor    : 1
   cache_alignment      : 64
   wkaras ~
   $
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to