Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
checking_thread_system.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef PAGESPEED_KERNEL_BASE_CHECKING_THREAD_SYSTEM_H_
20 #define PAGESPEED_KERNEL_BASE_CHECKING_THREAD_SYSTEM_H_
21 
23 
28 #include "pagespeed/kernel/base/thread_annotations.h"
29 
30 namespace net_instaweb {
31 
32 class Timer;
33 
43  private:
47  class CheckingCondvar;
48  public:
55  class LOCKABLE Mutex : public ThreadSystem::CondvarCapableMutex {
56  public:
57  explicit Mutex(ThreadSystem::CondvarCapableMutex* mutex) : mutex_(mutex) { }
58  virtual ~Mutex();
59 
60  virtual bool TryLock() EXCLUSIVE_TRYLOCK_FUNCTION(true);
61  virtual void Lock() EXCLUSIVE_LOCK_FUNCTION();
62  virtual void Unlock() UNLOCK_FUNCTION();
64  virtual void DCheckLocked();
65 
67  virtual void DCheckUnlocked();
68 
70  virtual ThreadSystem::Condvar* NewCondvar();
71 
72  private:
73  friend class CheckingCondvar;
74  void TakeLockControl();
75  void DropLockControl();
76 
78  AtomicBool locked_;
79 
80  };
81 
86  class LOCKABLE RWLock : public ThreadSystem::RWLock {
87  public:
88  explicit RWLock(ThreadSystem::RWLock* lock) : lock_(lock) { }
89  virtual ~RWLock();
90 
91  virtual bool TryLock() EXCLUSIVE_TRYLOCK_FUNCTION(true);
92  virtual void Lock() EXCLUSIVE_LOCK_FUNCTION();
93  virtual void Unlock() UNLOCK_FUNCTION();
94  virtual bool ReaderTryLock() SHARED_TRYLOCK_FUNCTION(true);
95  virtual void ReaderLock() SHARED_LOCK_FUNCTION();
96  virtual void ReaderUnlock() UNLOCK_FUNCTION();
97 
99  virtual void DCheckLocked();
100  virtual void DCheckReaderLocked();
101 
102  private:
103  void TakeLockControl();
104  void DropLockControl();
105  void TakeReaderLockControl();
106  void DropReaderLockControl();
107 
109  AtomicInt32 locked_;
110 
111  };
112 
113  explicit CheckingThreadSystem(ThreadSystem* thread_system)
114  : thread_system_(thread_system) { }
115  virtual ~CheckingThreadSystem();
116 
117  virtual Mutex* NewMutex();
118  virtual RWLock* NewRWLock();
119  virtual Timer* NewTimer();
120  virtual ThreadId* GetThreadId() const {
121  return thread_system_->GetThreadId();
122  }
123 
124  private:
125  friend class Mutex;
126 
127  virtual ThreadImpl* NewThreadImpl(Thread* wrapper, ThreadFlags flags);
128 
129  scoped_ptr<ThreadSystem> thread_system_;
130 
131 };
132 
133 }
134 
135 #endif
Definition: atomic_bool.h:31
Definition: condvar.h:27
Definition: atomic_int32.h:72
virtual ThreadId * GetThreadId() const
Definition: checking_thread_system.h:120
Definition: checking_thread_system.h:86
Definition: scoped_ptr.h:30
Definition: checking_thread_system.h:55
Definition: thread_system.h:61
Definition: thread_system.h:40
Definition: thread_system.h:116
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
Definition: checking_thread_system.h:42