Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mem_lock_manager.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_MANAGER_H_
20 #define PAGESPEED_KERNEL_BASE_MEM_LOCK_MANAGER_H_
21 
22 #include <map>
23 
30 
31 namespace net_instaweb {
32 
42  public:
43  static const int64 kNoWakeupsPending = -1;
44 
45  explicit MemLockManager(Timer* timer);
46  virtual ~MemLockManager();
47  virtual NamedLock* CreateNamedLock(const StringPiece& name);
48 
57  int64 NextWakeupTimeMs() const;
58 
60  void Wakeup();
61 
62  Timer* timer() const { return timer_; }
63 
67  bool IsHeldInOrderedSet(MemLock* lock) const;
68 
69  private:
70  typedef std::map<StringPiece, MemLockState*> MemLockStateMap;
71 
73  void RemoveLockState(MemLockState* lock_state);
74  void AddPendingLock(MemLock* lock);
75  void RemovePendingLock(MemLock* lock);
76 
77  friend class MemLockState;
78 
81  MemLockStateMap lock_state_map_;
82 
86  MemLockState::WakeupOrderedLockSet pending_locks_;
87 
88  Timer* timer_;
89  int64 sequence_;
90 };
91 
92 }
93 
94 #endif
Non-blocking locking class.
Definition: named_lock_manager.h:31
Definition: named_lock_manager.h:82
Captures and maintains scheduling order for locks with a common name.
Definition: mem_lock_state.h:34
Definition: mem_lock.h:31
Definition: mem_lock_manager.h:41
void Wakeup()
Runs any pending events (cancels, steals) for any pending locks.
bool IsHeldInOrderedSet(MemLock *lock) const
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
int64 NextWakeupTimeMs() const