Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
named_lock_schedule_rewrite_controller.h
Go to the documentation of this file.
1 // Copyright 2015 Google Inc.
16 
17 #ifndef PAGESPEED_CONTROLLER_NAMED_LOCK_SCHEDULE_REWRITE_CONTROLLER_H_
18 #define PAGESPEED_CONTROLLER_NAMED_LOCK_SCHEDULE_REWRITE_CONTROLLER_H_
19 
20 #include <unordered_set>
21 
32 #include "pagespeed/kernel/base/thread_annotations.h"
34 
35 namespace net_instaweb {
36 
40  public:
41  static const char kLocksGranted[];
42  static const char kLocksDenied[];
43  static const char kLocksStolen[];
44  static const char kLocksReleasedWhenNotHeld[];
45  static const char kLocksCurrentlyHeld[];
46 
47  static const int kStealMs;
48 
50  ThreadSystem* thread_system,
51  Statistics* statistics);
53 
55  virtual void ScheduleRewrite(const GoogleString& key, Function* callback);
56  virtual void NotifyRewriteComplete(const GoogleString& key);
57  virtual void NotifyRewriteFailed(const GoogleString& key);
58 
59  void ShutDown() override;
60 
61  static void InitStats(Statistics* stats);
62 
63  private:
64  struct LockInfo {
65  LockInfo() : pin_count(0) { }
68 
69  std::unordered_set<Function*> pending_callbacks;
70 
74  int pin_count;
75 
76  private:
77 
78  };
79 
80  typedef rde::hash_map<GoogleString, LockInfo*, CasePreserveStringHash>
81  LockMap;
82 
83  void LockObtained(Function* callback, const GoogleString key, NamedLock* lock)
84  LOCKS_EXCLUDED(mutex_);
85  void LockFailed(Function* callback, const GoogleString key, NamedLock* lock)
86  LOCKS_EXCLUDED(mutex_);
87 
88  LockInfo* GetLockInfo(const GoogleString& key)
89  EXCLUSIVE_LOCKS_REQUIRED(mutex_);
90  void DeleteInfoIfUnused(LockInfo* info, const GoogleString& key)
91  EXCLUSIVE_LOCKS_REQUIRED(mutex_);
92 
94  NamedLockManager* lock_manager_;
95  LockMap locks_ GUARDED_BY(mutex_);
96  bool shut_down_ GUARDED_BY(mutex_);
97 
98  TimedVariable* locks_granted_;
99  TimedVariable* locks_denied_;
100  TimedVariable* locks_stolen_;
101  TimedVariable* locks_released_when_not_held_;
102  UpDownCounter* locks_currently_held_;
103 
104 
105 };
106 
107 }
108 
109 #endif
Non-blocking locking class.
Definition: named_lock_manager.h:31
Definition: named_lock_manager.h:82
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
virtual void ScheduleRewrite(const GoogleString &key, Function *callback)
ScheduleRewriteController interface.
Definition: scoped_ptr.h:30
Definition: function.h:47
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: named_lock_schedule_rewrite_controller.h:39
Definition: thread_system.h:40
virtual void NotifyRewriteComplete(const GoogleString &key)
Definition: statistics.h:73
Definition: statistics.h:298
Definition: schedule_rewrite_controller.h:30