Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
worker_test_base.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  */
17 
20 
21 #include "base/logging.h"
28 
29 #ifndef PAGESPEED_KERNEL_THREAD_WORKER_TEST_BASE_H_
30 #define PAGESPEED_KERNEL_THREAD_WORKER_TEST_BASE_H_
31 
32 namespace net_instaweb {
33 
34 class WorkerTestBase : public ::testing::Test {
35  public:
36  class CountFunction;
37  class SyncPoint;
38  class NotifyRunFunction;
39  class WaitRunFunction;
40  class FailureFunction;
41 
43  ~WorkerTestBase();
44 
45  protected:
46  scoped_ptr<ThreadSystem> thread_runtime_;
47 
48  private:
49 
50 };
51 
54  public:
55  explicit CountFunction(int* variable) : variable_(variable) {}
56 
57  virtual void Run() {
58  ++*variable_;
59  }
60 
61  virtual void Cancel() {
62  *variable_ -= 100;
63  }
64 
65  private:
66  int* variable_;
67 
68 };
69 
72  public:
73  explicit SyncPoint(ThreadSystem* thread_system);
74 
75  void Wait();
76  void Notify();
77 
78  private:
79  bool done_;
82 
83 };
84 
87  public:
88  explicit NotifyRunFunction(SyncPoint* sync);
89  virtual void Run();
90 
91  private:
92  SyncPoint* sync_;
93 
94 };
95 
98  public:
99  explicit WaitRunFunction(SyncPoint* sync);
100  virtual void Run();
101 
102  private:
103  SyncPoint* sync_;
104 
105 };
106 
109  public:
111  : sync_(sync) {}
112  virtual ~DeleteNotifyFunction() {
113  sync_->Notify();
114  }
115 
116  virtual void Run() {
117  LOG(FATAL) << "DeleteNotifyFunction ran.";
118  }
119 
120  private:
122 
123 };
124 
125 }
126 
127 #endif
virtual void Run()
Definition: worker_test_base.h:57
Waits on a given SyncPoint before completing Run()
Definition: worker_test_base.h:97
Definition: worker_test_base.h:34
A closure that increments a variable on running.
Definition: worker_test_base.h:53
virtual void Run()
Definition: worker_test_base.h:116
A way for one thread to wait for another.
Definition: worker_test_base.h:71
Definition: scoped_ptr.h:30
Definition: function.h:47
Notifies of itself having run on a given SyncPoint.
Definition: worker_test_base.h:86
virtual void Cancel()
Definition: worker_test_base.h:61
Definition: thread_system.h:40
Function that signals on destruction and check fails when run.
Definition: worker_test_base.h:108