Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lock_manager_spammer.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  */
17 
19 
20 #ifndef PAGESPEED_KERNEL_UTIL_LOCK_MANAGER_SPAMMER_H_
21 #define PAGESPEED_KERNEL_UTIL_LOCK_MANAGER_SPAMMER_H_
22 
23 #include <vector>
24 
31 #include "pagespeed/kernel/base/thread_annotations.h"
34 
35 namespace net_instaweb {
36 
37 class ThreadSafeLockManager;
38 
42  public:
43  virtual ~LockManagerSpammer();
44 
49  static void RunTests(int num_threads, int num_iters, int num_names,
50  bool expecting_denials, bool delay_unlocks,
51  ThreadSafeLockManager* lock_manager,
52  Scheduler* scheduler);
53 
55  void Granted(NamedLock* lock);
56  void UnlockAfterGrant(NamedLock* lock);
57  void Denied(NamedLock* lock);
58 
59  protected:
60  virtual void Run();
61 
62  private:
63  class CountDown {
64  public:
65  CountDown(Scheduler* scheduler, int initial_value);
66  ~CountDown();
67 
68  void Decrement();
69  void RunAlarmsTillThreadsComplete();
70 
71  private:
72  Scheduler* scheduler_;
73  int value_ GUARDED_BY(scheduler_->mutex());
74  };
75 
76  typedef std::vector<NamedLock*> LockVector;
77 
78  LockManagerSpammer(Scheduler* scheduler,
79  ThreadSystem::ThreadFlags flags,
80  const StringVector& lock_names,
81  ThreadSafeLockManager* lock_manager,
82  bool expecting_denials,
83  bool delay_unlocks,
84  int index,
85  int num_iters,
86  int num_names,
87  CountDown* pending_threads);
88 
89  Scheduler* scheduler_;
90  const StringVector& lock_names_;
91  ThreadSafeLockManager* lock_manager_;
92  bool expecting_denials_;
93  bool delay_unlocks_;
94  int index_;
95  int num_iters_;
96  int num_names_;
99  int grants_ GUARDED_BY(mutex_);
100  int denials_ GUARDED_BY(mutex_);
101  LockVector queued_unlocks_ GUARDED_BY(mutex_);
102  CountDown* pending_threads_;
103 
104 
105 };
106 
107 }
108 
109 #endif
void Granted(NamedLock *lock)
Called when a lock is granted/denied.
Non-blocking locking class.
Definition: named_lock_manager.h:31
static void RunTests(int num_threads, int num_iters, int num_names, bool expecting_denials, bool delay_unlocks, ThreadSafeLockManager *lock_manager, Scheduler *scheduler)
Definition: scoped_ptr.h:30
Definition: lock_manager_spammer.h:41
Threadsafe wrapper for a non-threadsafe lock manager: MemLockManager.
Definition: threadsafe_lock_manager.h:30
Definition: scheduler.h:47
Base class for client thread code.
Definition: thread.h:34