Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mem_lock.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_H_
20 #define PAGESPEED_KERNEL_BASE_MEM_LOCK_H_
21 
25 
26 namespace net_instaweb {
27 
28 class Function;
29 class MemLockState;
30 
31 class MemLock : public NamedLock {
32  public:
33  static const int64 kDoNotSteal = -1;
34  static const int64 kNotHeld = -1;
35  static const int64 kNotPending = -1;
36 
37  virtual void LockTimedWait(int64 wait_ms, Function* callback);
38  virtual void LockTimedWaitStealOld(int64 wait_ms, int64 steal_ms,
39  Function* callback);
40  virtual void Unlock();
41  virtual GoogleString name() const;
42  virtual bool Held() { return grant_time_ms_ != kNotHeld; }
43 
46  void Wakeup();
47 
52  int64 wakeup_time_ms() const { return wakeup_time_ms_; }
53 
61  int StableCompare(const MemLock* that) const;
62 
63  private:
64  friend class MemLockState;
65 
67  MemLock(int64 sequence, MemLockState* lock_state);
68  virtual ~MemLock();
69 
71  int64 grant_time_ms() const { return grant_time_ms_; }
72 
76  int64 steal_ms() const { return steal_ms_; }
77 
80  void Grant(int64 grant_time_ms);
81 
85  void Deny();
86 
96  void CalculateWakeupTime(int64 held_lock_grant_time_ms);
97 
99  bool CanSteal() const { return steal_ms_ != kDoNotSteal; }
100 
102  bool IsPending() const { return wakeup_time_ms_ != kNotPending; }
103 
106  void Clear();
107 
110  bool ShouldCancelOnWakeup() const {
111  return cancel_time_ms_ == wakeup_time_ms_;
112  }
113 
114  MemLockState* lock_state_;
115  Function* callback_;
116 
117  int64 cancel_time_ms_;
118  int64 grant_time_ms_;
119  int64 sequence_;
120 
123  int64 steal_ms_;
124  int64 wakeup_time_ms_;
125 };
126 
127 }
128 
129 #endif
virtual void Unlock()
Non-blocking locking class.
Definition: named_lock_manager.h:31
int StableCompare(const MemLock *that) const
virtual bool Held()
Definition: mem_lock.h:42
virtual void LockTimedWait(int64 wait_ms, Function *callback)
Captures and maintains scheduling order for locks with a common name.
Definition: mem_lock_state.h:34
Definition: mem_lock.h:31
Definition: function.h:47
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
int64 wakeup_time_ms() const
Definition: mem_lock.h:52
virtual GoogleString name() const
The name the lock was created with, for debugging/logging purposes.
virtual void LockTimedWaitStealOld(int64 wait_ms, int64 steal_ms, Function *callback)