Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mem_lock_state.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 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_MEM_LOCK_STATE_H_
20 #define PAGESPEED_KERNEL_BASE_MEM_LOCK_STATE_H_
21 
22 #include <set>
23 
27 
28 namespace net_instaweb {
29 
30 class MemLock;
31 class MemLockManager;
32 
34 class MemLockState {
35  public:
40 
51  struct Comparator {
52  bool operator()(const MemLock* a, const MemLock* b) const;
53  };
54 
57  struct StealComparator {
58  bool operator()(const MemLock* a, const MemLock* b) const;
59  };
60 
61  typedef std::set<MemLock*, MemLockState::Comparator> WakeupOrderedLockSet;
62  typedef std::set<MemLock*, MemLockState::StealComparator> StealOrderedLockSet;
63 
64  const GoogleString& name() const { return name_; }
65 
70  MemLock* CreateLock(int64 sequence);
71 
74  void RemoveLock(MemLock* lock);
75 
78  void UnscheduleLock(MemLock* lock);
79 
82  void ScheduleLock(MemLock* lock);
83 
88  bool GrabLock(MemLock* lock);
89 
92  void Unlock();
93 
97  void StealLock(MemLock* lock);
98 
99  MemLockManager* manager() { return manager_; }
100 
104  bool IsHeldInOrderedSet(MemLock* lock) const;
105 
106  template<typename T>
107  static int Compare(const T& a, const T& b) {
108  if (a < b) {
109  return -1;
110  } else if (a > b) {
111  return 1;
112  }
113  return 0;
114  }
115 
116  private:
117  friend class MemLockManager;
118 
122  MemLockState(StringPiece name, MemLockManager* manager);
123  ~MemLockState();
124 
126  void MemLockManagerDestroyed();
127 
131  void RescheduleLock(int64 held_lock_grant_time_ms, MemLock* lock);
132 
133  MemLock* current_owner_;
134  int64 lock_count_;
135  WakeupOrderedLockSet pending_locks_;
136  StealOrderedLockSet pending_steals_;
137  GoogleString name_;
138  MemLockManager* manager_;
139 };
140 
141 }
142 
143 #endif
Definition: mem_lock_state.h:51
Captures and maintains scheduling order for locks with a common name.
Definition: mem_lock_state.h:34
Definition: mem_lock.h:31
void StealLock(MemLock *lock)
Definition: mem_lock_manager.h:41
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
bool GrabLock(MemLock *lock)
bool IsHeldInOrderedSet(MemLock *lock) const
void ScheduleLock(MemLock *lock)
Definition: mem_lock_state.h:57
MemLock * CreateLock(int64 sequence)
void UnscheduleLock(MemLock *lock)
void RemoveLock(MemLock *lock)
Called when lock is deleted.