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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef NET_QUIC_PLATFORM_API_QUIC_MUTEX_H_
6 #define NET_QUIC_PLATFORM_API_QUIC_MUTEX_H_
7
8 #include "net/quic/platform/impl/quic_mutex_impl.h"
9
10 namespace net {
11
12 // A class representing a non-reentrant mutex in QUIC.
13 class QUIC_EXPORT_PRIVATE LOCKABLE QuicMutex {
14 public:
15 QuicMutex() = default;
16
17 // Block until this Mutex is free, then acquire it exclusively.
18 void WriterLock() EXCLUSIVE_LOCK_FUNCTION();
19
20 // Release this Mutex. Caller must hold it exclusively.
21 void WriterUnlock() UNLOCK_FUNCTION();
22
23 // Block until this Mutex is free or shared, then acquire a share of it.
24 void ReaderLock() SHARED_LOCK_FUNCTION();
25
26 // Release this Mutex. Caller could hold it in shared mode.
27 void ReaderUnlock() UNLOCK_FUNCTION();
28
29 // Returns immediately if current thread holds the Mutex in at least shared
30 // mode. Otherwise, may report an error (typically by crashing with a
31 // diagnostic), or may return immediately.
32 void AssertReaderHeld() const ASSERT_SHARED_LOCK();
33
34 private:
35 QuicLockImpl impl_;
36
37 DISALLOW_COPY_AND_ASSIGN(QuicMutex);
38 };
39
40 // A helper class that acquires the given QuicMutex shared lock while the
41 // QuicReaderMutexLock is in scope.
42 class QUIC_EXPORT_PRIVATE SCOPED_LOCKABLE QuicReaderMutexLock {
43 public:
44 explicit QuicReaderMutexLock(QuicMutex* lock) SHARED_LOCK_FUNCTION(lock);
45
46 ~QuicReaderMutexLock() UNLOCK_FUNCTION();
47
48 private:
49 QuicMutex* const lock_;
50
51 DISALLOW_COPY_AND_ASSIGN(QuicReaderMutexLock);
52 };
53
54 // A helper class that acquires the given QuicMutex exclusive lock while the
55 // QuicWriterMutexLock is in scope.
56 class QUIC_EXPORT_PRIVATE SCOPED_LOCKABLE QuicWriterMutexLock {
57 public:
58 explicit QuicWriterMutexLock(QuicMutex* lock) EXCLUSIVE_LOCK_FUNCTION(lock);
59
60 ~QuicWriterMutexLock() UNLOCK_FUNCTION();
61
62 private:
63 QuicMutex* const lock_;
64
65 DISALLOW_COPY_AND_ASSIGN(QuicWriterMutexLock);
66 };
67
68 } // namespace net
69
70 #endif // NET_QUIC_PLATFORM_API_QUIC_MUTEX_H_
OLDNEW
« 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