Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
blocking_callback.h
1 /*
2  * Copyright 2016 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 #ifndef PAGESPEED_KERNEL_THREAD_BLOCKING_CALLBACK_H_
17 #define PAGESPEED_KERNEL_THREAD_BLOCKING_CALLBACK_H_
18 
25 
26 namespace net_instaweb {
27 
30  public:
31  explicit BlockingCallback(ThreadSystem* threads)
32  : sync_(threads), result_(CacheInterface::kNotFound) {}
33 
34  CacheInterface::KeyState result() const { return result_; }
35  GoogleString value() const { return value_; }
36 
37  void Block() {
38  sync_.Wait();
39  }
40 
41  protected:
42  virtual void Done(CacheInterface::KeyState state) {
43  result_ = state;
44  CacheInterface::Callback::value().Value().CopyToString(&value_);
45  sync_.Notify();
46  }
47 
48  private:
51  GoogleString value_;
52 };
53 
54 }
55 
56 #endif
Requested key needs to be written.
Definition: cache_interface.h:36
KeyState
Definition: cache_interface.h:34
A way for one thread to wait for another.
Definition: worker_test_base.h:71
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: cache_interface.h:42
virtual void Done(CacheInterface::KeyState state)
Definition: blocking_callback.h:42
Definition: thread_system.h:40
Helper that blocks for async cache lookups. Used in tests.
Definition: blocking_callback.h:29