Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
mock_scheduler.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 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_THREAD_MOCK_SCHEDULER_H_
20 #define PAGESPEED_KERNEL_THREAD_MOCK_SCHEDULER_H_
21 
23 #include "pagespeed/kernel/base/thread_annotations.h"
28 
29 namespace net_instaweb {
30 
31 class MockTimer;
32 
39 class MockScheduler : public Scheduler {
40  public:
42  MockTimer* timer);
43  virtual ~MockScheduler();
44 
46  LOCKS_EXCLUDED(mutex());
47  virtual void UnregisterWorker(QueuedWorkerPool::Sequence* w)
48  LOCKS_EXCLUDED(mutex());
49 
51  void AwaitQuiescence() LOCKS_EXCLUDED(mutex());
52 
54  void AdvanceTimeMs(int64 timeout_ms) LOCKS_EXCLUDED(mutex()) {
55  AdvanceTimeUs(timeout_ms * Timer::kMsUs);
56  }
57  void AdvanceTimeUs(int64 timeout_us) LOCKS_EXCLUDED(mutex());
58 
60  void SetTimeUs(int64 time_us) LOCKS_EXCLUDED(mutex());
61 
62  protected:
63  virtual void AwaitWakeupUntilUs(int64 wakeup_time_us)
64  EXCLUSIVE_LOCKS_REQUIRED(mutex());
65 
66  private:
67  inline void SetTimeUsMutexHeld(int64 time_us)
68  EXCLUSIVE_LOCKS_REQUIRED(mutex());
69 
72  MockTimer* timer_;
73  QueuedWorkerPool::SequenceSet workers_ GUARDED_BY(mutex());
74 
75 
76 };
77 
78 }
79 
80 #endif
Definition: mock_timer.h:33
Definition: mock_scheduler.h:39
virtual void RegisterWorker(QueuedWorkerPool::Sequence *w) LOCKS_EXCLUDED(mutex())
void SetTimeUs(int64 time_us) LOCKS_EXCLUDED(mutex())
Sets the current absolute time using absolute numbers.
Timer * timer()
Definition: scheduler.h:154
void AdvanceTimeMs(int64 timeout_ms) LOCKS_EXCLUDED(mutex())
Similar to BlockingTimedWaitUs but takes the lock for convenience.
Definition: mock_scheduler.h:54
Definition: queued_worker_pool.h:65
virtual void AwaitWakeupUntilUs(int64 wakeup_time_us) EXCLUSIVE_LOCKS_REQUIRED(mutex())
Definition: thread_system.h:40
Definition: scheduler.h:47
ThreadSystem * thread_system()
Obtain the thread system used by the scheduler.
Definition: scheduler.h:157
void AwaitQuiescence() LOCKS_EXCLUDED(mutex())
Blocks until all work in registered workers is done.