Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
null_thread_system.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013 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 
25 
26 #ifndef PAGESPEED_KERNEL_BASE_NULL_THREAD_SYSTEM_H_
27 #define PAGESPEED_KERNEL_BASE_NULL_THREAD_SYSTEM_H_
28 
29 #include "base/logging.h"
35 
36 namespace net_instaweb {
37 
38 class Timer;
39 
41  public:
43  : mutex_(m), timed_wait_callback_(NULL) {}
44  virtual ~NullCondvar();
45  virtual ThreadSystem::CondvarCapableMutex* mutex() const { return mutex_; }
46  virtual void Signal() { actions_.push_back("Signal()"); }
47  virtual void Broadcast() { actions_.push_back("Broadcast()"); }
48  virtual void Wait() { actions_.push_back("Wait()"); }
49  virtual void TimedWait(int64 timeout_ms);
50  GoogleString ActionsSinceLastCall();
51 
53  public:
54  virtual ~TimedWaitCallback() {}
55  virtual void Call() = 0;
56  };
57 
61  CHECK(timed_wait_callback_ == NULL);
62  timed_wait_callback_ = x;
63  }
64 
65  private:
67  StringVector actions_;
68  TimedWaitCallback* timed_wait_callback_;
69 
70 
71 };
72 
76  public:
78  virtual ~NullCondvarCapableMutex();
79  virtual bool TryLock() { return true; }
80  virtual void Lock() {}
81  virtual void Unlock() {}
82  virtual NullCondvar* NewCondvar();
83 
84  private:
85 
86 };
87 
92  public:
93  NullThreadSystem() : thread_id_(1) {}
94  virtual ~NullThreadSystem();
96  virtual RWLock* NewRWLock();
97  virtual Timer* NewTimer();
98  virtual ThreadId* GetThreadId() const;
99 
101  void set_current_thread(int id) { thread_id_ = id; }
102  int current_thread() const { return thread_id_; }
103 
104  private:
105  virtual ThreadImpl* NewThreadImpl(Thread* wrapper, ThreadFlags flags);
106 
107  private:
108  int thread_id_;
109 
110 
111 };
112 
113 }
114 
115 #endif
virtual void TimedWait(int64 timeout_ms)
virtual bool TryLock()
Attempt to take mutex, true on success, false if held by another thread.
Definition: null_thread_system.h:79
virtual NullCondvarCapableMutex * NewMutex()
void set_current_thread(int id)
Provide injection/observation of current thread IDs.
Definition: null_thread_system.h:101
Definition: condvar.h:27
virtual void Lock()
Block until mutex is available, then take the mutex.
Definition: null_thread_system.h:80
virtual void Wait()
Definition: null_thread_system.h:48
virtual ThreadSystem::CondvarCapableMutex * mutex() const
Return the mutex associated with this condition variable.
Definition: null_thread_system.h:45
void set_timed_wait_callback(TimedWaitCallback *x)
Definition: null_thread_system.h:60
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: thread_system.h:61
Definition: null_thread_system.h:40
Definition: null_thread_system.h:52
Definition: thread_system.h:40
virtual RWLock * NewRWLock()
Definition: null_thread_system.h:75
virtual void Unlock()
Release the mutex, permitting a blocked lock operation (if any) to proceed.
Definition: null_thread_system.h:81
virtual void Broadcast()
Definition: null_thread_system.h:47
Definition: thread_system.h:116
virtual void Signal()
Definition: null_thread_system.h:46
Timer interface, made virtual so it can be mocked for tests.
Definition: timer.h:27
Definition: null_thread_system.h:91
virtual NullCondvar * NewCondvar()
Creates a new condition variable associated with 'this' mutex.
virtual ThreadId * GetThreadId() const