Restructure QUICHE platform by splitting it into "default" and "overrides".
This demonstrates an example where a default is used directly in google3 (quic_mutex) and where a google3-specific override exists (quic_testvalue).
PiperOrigin-RevId: 354158548
Change-Id: I1036ede80cd354c494b43916fa1876d47891785a
diff --git a/common/platform/default/quiche_platform_impl/quic_mutex_impl.cc b/common/platform/default/quiche_platform_impl/quic_mutex_impl.cc
new file mode 100644
index 0000000..8c9081f
--- /dev/null
+++ b/common/platform/default/quiche_platform_impl/quic_mutex_impl.cc
@@ -0,0 +1,25 @@
+#include "quiche_platform_impl/quic_mutex_impl.h"
+
+namespace quic {
+
+void QuicLockImpl::WriterLock() {
+ mu_.WriterLock();
+}
+
+void QuicLockImpl::WriterUnlock() {
+ mu_.WriterUnlock();
+}
+
+void QuicLockImpl::ReaderLock() {
+ mu_.ReaderLock();
+}
+
+void QuicLockImpl::ReaderUnlock() {
+ mu_.ReaderUnlock();
+}
+
+void QuicLockImpl::AssertReaderHeld() const {
+ mu_.AssertReaderHeld();
+}
+
+} // namespace quic
diff --git a/common/platform/default/quiche_platform_impl/quic_mutex_impl.h b/common/platform/default/quiche_platform_impl/quic_mutex_impl.h
new file mode 100644
index 0000000..b21ef7d
--- /dev/null
+++ b/common/platform/default/quiche_platform_impl/quic_mutex_impl.h
@@ -0,0 +1,68 @@
+#ifndef QUICHE_COMMON_PLATFORM_DEFAULT_QUICHE_PLATFORM_IMPL_QUIC_MUTEX_IMPL_H_
+#define QUICHE_COMMON_PLATFORM_DEFAULT_QUICHE_PLATFORM_IMPL_QUIC_MUTEX_IMPL_H_
+
+#include "absl/synchronization/mutex.h"
+#include "absl/synchronization/notification.h"
+#include "quic/platform/api/quic_export.h"
+
+#define QUIC_EXCLUSIVE_LOCKS_REQUIRED_IMPL ABSL_EXCLUSIVE_LOCKS_REQUIRED
+#define QUIC_GUARDED_BY_IMPL ABSL_GUARDED_BY
+#define QUIC_LOCKABLE_IMPL ABSL_LOCKABLE
+#define QUIC_LOCKS_EXCLUDED_IMPL ABSL_LOCKS_EXCLUDED
+#define QUIC_SHARED_LOCKS_REQUIRED_IMPL ABSL_SHARED_LOCKS_REQUIRED
+#define QUIC_EXCLUSIVE_LOCK_FUNCTION_IMPL ABSL_EXCLUSIVE_LOCK_FUNCTION
+#define QUIC_UNLOCK_FUNCTION_IMPL ABSL_UNLOCK_FUNCTION
+#define QUIC_SHARED_LOCK_FUNCTION_IMPL ABSL_SHARED_LOCK_FUNCTION
+#define QUIC_SCOPED_LOCKABLE_IMPL ABSL_SCOPED_LOCKABLE
+#define QUIC_ASSERT_SHARED_LOCK_IMPL ABSL_ASSERT_SHARED_LOCK
+
+namespace quic {
+
+// A class wrapping a non-reentrant mutex.
+class ABSL_LOCKABLE QUIC_EXPORT_PRIVATE QuicLockImpl {
+ public:
+ QuicLockImpl() = default;
+ QuicLockImpl(const QuicLockImpl&) = delete;
+ QuicLockImpl& operator=(const QuicLockImpl&) = delete;
+
+ // Block until mu_ is free, then acquire it exclusively.
+ void WriterLock() ABSL_EXCLUSIVE_LOCK_FUNCTION();
+
+ // Release mu_. Caller must hold it exclusively.
+ void WriterUnlock() ABSL_UNLOCK_FUNCTION();
+
+ // Block until mu_ is free or shared, then acquire a share of it.
+ void ReaderLock() ABSL_SHARED_LOCK_FUNCTION();
+
+ // Release mu_. Caller could hold it in shared mode.
+ void ReaderUnlock() ABSL_UNLOCK_FUNCTION();
+
+ // Returns immediately if current thread holds mu_ in at least shared
+ // mode. Otherwise, reports an error by crashing with a diagnostic.
+ void AssertReaderHeld() const ABSL_ASSERT_SHARED_LOCK();
+
+ private:
+ absl::Mutex mu_;
+};
+
+// A Notification allows threads to receive notification of a single occurrence
+// of a single event.
+class QUIC_EXPORT_PRIVATE QuicNotificationImpl {
+ public:
+ QuicNotificationImpl() = default;
+ QuicNotificationImpl(const QuicNotificationImpl&) = delete;
+ QuicNotificationImpl& operator=(const QuicNotificationImpl&) = delete;
+
+ bool HasBeenNotified() { return notification_.HasBeenNotified(); }
+
+ void Notify() { notification_.Notify(); }
+
+ void WaitForNotification() { notification_.WaitForNotification(); }
+
+ private:
+ absl::Notification notification_;
+};
+
+} // namespace quic
+
+#endif // QUICHE_COMMON_PLATFORM_DEFAULT_QUICHE_PLATFORM_IMPL_QUIC_MUTEX_IMPL_H_
diff --git a/common/platform/default/quiche_platform_impl/quic_testvalue_impl.h b/common/platform/default/quiche_platform_impl/quic_testvalue_impl.h
new file mode 100644
index 0000000..f4678e7
--- /dev/null
+++ b/common/platform/default/quiche_platform_impl/quic_testvalue_impl.h
@@ -0,0 +1,13 @@
+#ifndef QUICHE_COMMON_PLATFORM_DEFAULT_QUIC_TESTVALUE_IMPL_H_
+#define QUICHE_COMMON_PLATFORM_DEFAULT_QUIC_TESTVALUE_IMPL_H_
+
+#include "absl/strings/string_view.h"
+
+namespace quic {
+
+template <class T>
+void AdjustTestValueImpl(absl::string_view /*label*/, T* /*var*/) {}
+
+} // namespace quic
+
+#endif // QUICHE_COMMON_PLATFORM_DEFAULT_QUIC_TESTVALUE_IMPL_H_
diff --git a/quic/platform/api/quic_mutex.h b/quic/platform/api/quic_mutex.h
index d35c660..33f01e4 100644
--- a/quic/platform/api/quic_mutex.h
+++ b/quic/platform/api/quic_mutex.h
@@ -5,7 +5,8 @@
#ifndef QUICHE_QUIC_PLATFORM_API_QUIC_MUTEX_H_
#define QUICHE_QUIC_PLATFORM_API_QUIC_MUTEX_H_
-#include "net/quic/platform/impl/quic_mutex_impl.h"
+// TODO(b/178613777): move into the common QUICHE platform.
+#include "quiche_platform_impl/quic_mutex_impl.h"
#define QUIC_EXCLUSIVE_LOCKS_REQUIRED QUIC_EXCLUSIVE_LOCKS_REQUIRED_IMPL
#define QUIC_GUARDED_BY QUIC_GUARDED_BY_IMPL
diff --git a/quic/platform/api/quic_testvalue.h b/quic/platform/api/quic_testvalue.h
index 96ce968..58bc4f4 100644
--- a/quic/platform/api/quic_testvalue.h
+++ b/quic/platform/api/quic_testvalue.h
@@ -6,7 +6,9 @@
#define QUICHE_QUIC_PLATFORM_API_QUIC_TESTVALUE_H_
#include "absl/strings/string_view.h"
-#include "net/quic/platform/impl/quic_testvalue_impl.h"
+
+// TODO(b/178613777): move into the common QUICHE platform.
+#include "quiche_platform_impl/quic_testvalue_impl.h"
namespace quic {