Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dependency_tracker.h
Go to the documentation of this file.
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  */
17 
18 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DEPENDENCY_TRACKER_H_
19 #define NET_INSTAWEB_REWRITER_PUBLIC_DEPENDENCY_TRACKER_H_
20 
21 #include <memory>
22 
23 #include "net/instaweb/rewriter/dependencies.pb.h"
27 #include "pagespeed/kernel/base/thread_annotations.h"
28 
29 namespace net_instaweb {
30 
31 class AbstractMutex;
32 class RewriteDriver;
33 class ServerContext;
34 
42  public:
44  explicit DependencyTracker(RewriteDriver* driver);
46 
48  void SetServerContext(ServerContext* server_context);
49 
51  void Start();
52 
55  void FinishedParsing();
56 
61 
73  void ReportDependencyCandidate(int id, const Dependency* dep);
74 
76  const Dependencies* read_in_info() const { return read_in_info_.get(); }
77 
78  private:
79  void Clear() LOCKS_EXCLUDED(mutex_);
80  void ClearLockHeld() EXCLUSIVE_LOCKS_REQUIRED(mutex_);
81  void WriteToPropertyCacheIfDone() EXCLUSIVE_LOCKS_REQUIRED(mutex_);
82 
83  RewriteDriver* driver_;
84 
85  std::unique_ptr<AbstractMutex> mutex_;
86 
89  std::unique_ptr<Dependencies> read_in_info_;
90 
93  std::map<int, Dependency> computed_info_ GUARDED_BY(mutex_);
94 
95  int next_id_ GUARDED_BY(mutex_);
96  int outstanding_candidates_ GUARDED_BY(mutex_);
97 
100  bool saw_end_ GUARDED_BY(mutex_);
101 
102 
103 };
104 
105 
108  public:
109  bool operator()(const Dependency& a, const Dependency& b);
110 };
111 
112 }
113 
114 #endif
void Start()
Must be called when parsing pages, after pcache has read in.
const Dependencies * read_in_info() const
This is temporary, nicer API coming later.
Definition: dependency_tracker.h:76
Abstract interface for implementing a mutex.
Definition: abstract_mutex.h:28
void ReportDependencyCandidate(int id, const Dependency *dep)
Compares two Dependency objects based on the order_key field.
Definition: dependency_tracker.h:107
Definition: rewrite_driver.h:100
Definition: server_context.h:99
void SetServerContext(ServerContext *server_context)
This needs to be called to help initialize locking.
DependencyTracker(RewriteDriver *driver)
Note: you must also call SetServerContext on this before operation.
Definition: dependency_tracker.h:41