Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1546)

Unified Diff: net/quic/platform/api/quic_mutex.h

Issue 2561913003: Create a QUIC wrapper around a mutex and a mutex lock. (Closed)
Patch Set: fix Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/quic/core/crypto/quic_crypto_server_config.cc ('k') | net/quic/platform/api/quic_mutex.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/quic/platform/api/quic_mutex.h
diff --git a/net/quic/platform/api/quic_mutex.h b/net/quic/platform/api/quic_mutex.h
new file mode 100644
index 0000000000000000000000000000000000000000..cc51f304881f2d02078afbd24edd224670d001f5
--- /dev/null
+++ b/net/quic/platform/api/quic_mutex.h
@@ -0,0 +1,70 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_QUIC_PLATFORM_API_QUIC_MUTEX_H_
+#define NET_QUIC_PLATFORM_API_QUIC_MUTEX_H_
+
+#include "net/quic/platform/impl/quic_mutex_impl.h"
+
+namespace net {
+
+// A class representing a non-reentrant mutex in QUIC.
+class QUIC_EXPORT_PRIVATE LOCKABLE QuicMutex {
+ public:
+ QuicMutex() = default;
+
+ // Block until this Mutex is free, then acquire it exclusively.
+ void WriterLock() EXCLUSIVE_LOCK_FUNCTION();
+
+ // Release this Mutex. Caller must hold it exclusively.
+ void WriterUnlock() UNLOCK_FUNCTION();
+
+ // Block until this Mutex is free or shared, then acquire a share of it.
+ void ReaderLock() SHARED_LOCK_FUNCTION();
+
+ // Release this Mutex. Caller could hold it in shared mode.
+ void ReaderUnlock() UNLOCK_FUNCTION();
+
+ // Returns immediately if current thread holds the Mutex in at least shared
+ // mode. Otherwise, may report an error (typically by crashing with a
+ // diagnostic), or may return immediately.
+ void AssertReaderHeld() const ASSERT_SHARED_LOCK();
+
+ private:
+ QuicLockImpl impl_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuicMutex);
+};
+
+// A helper class that acquires the given QuicMutex shared lock while the
+// QuicReaderMutexLock is in scope.
+class QUIC_EXPORT_PRIVATE SCOPED_LOCKABLE QuicReaderMutexLock {
+ public:
+ explicit QuicReaderMutexLock(QuicMutex* lock) SHARED_LOCK_FUNCTION(lock);
+
+ ~QuicReaderMutexLock() UNLOCK_FUNCTION();
+
+ private:
+ QuicMutex* const lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuicReaderMutexLock);
+};
+
+// A helper class that acquires the given QuicMutex exclusive lock while the
+// QuicWriterMutexLock is in scope.
+class QUIC_EXPORT_PRIVATE SCOPED_LOCKABLE QuicWriterMutexLock {
+ public:
+ explicit QuicWriterMutexLock(QuicMutex* lock) EXCLUSIVE_LOCK_FUNCTION(lock);
+
+ ~QuicWriterMutexLock() UNLOCK_FUNCTION();
+
+ private:
+ QuicMutex* const lock_;
+
+ DISALLOW_COPY_AND_ASSIGN(QuicWriterMutexLock);
+};
+
+} // namespace net
+
+#endif // NET_QUIC_PLATFORM_API_QUIC_MUTEX_H_
« no previous file with comments | « net/quic/core/crypto/quic_crypto_server_config.cc ('k') | net/quic/platform/api/quic_mutex.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698