22 #include "syncpoint_call_stats.h"
24 #include <core/threading/mutex_locker.h>
25 #include <syncpoint/exceptions.h>
26 #include <syncpoint/syncpoint_manager.h>
50 SyncPointManager::~SyncPointManager()
71 return get_syncpoint_no_lock(component, identifier);
89 release_syncpoint_no_lock(component, sync_point);
107 return **sp1 < **sp2;
128 SyncPointManager::find_prefix(
const std::string &identifier)
const
130 size_t last_pos = identifier.rfind(
"/");
132 return identifier.substr(0, last_pos);
139 SyncPointManager::get_syncpoint_no_lock(
const std::string &component,
const std::string &identifier)
141 if (component ==
"") {
142 throw SyncPointInvalidComponentException(component.c_str(), identifier.c_str());
146 std::pair<std::set<RefPtr<SyncPoint>>::iterator,
bool> insert_ret;
147 insert_ret =
syncpoints_.insert(RefPtr<SyncPoint>(
new SyncPoint(identifier, logger_)));
148 std::set<RefPtr<SyncPoint>>::iterator sp_it = insert_ret.first;
151 (*sp_it)->add_watcher(component);
153 if (identifier !=
"/") {
156 std::string prefix = find_prefix(identifier);
157 RefPtr<SyncPoint> predecessor = get_syncpoint_no_lock(component, prefix);
158 predecessor->successors_.insert(*sp_it);
159 (*sp_it)->predecessor_ = predecessor;
166 SyncPointManager::release_syncpoint_no_lock(
const std::string &component,
167 RefPtr<SyncPoint> sync_point)
169 std::set<RefPtr<SyncPoint>>::iterator sp_it =
syncpoints_.find(sync_point);
171 throw SyncPointReleasedDoesNotExistException(component.c_str(),
172 sync_point->get_identifier().c_str());
174 if (component_watches_any_successor(sync_point, component)) {
178 (*sp_it)->unwait(component);
179 if (!(*sp_it)->watchers_.erase(component)) {
180 throw SyncPointReleasedByNonWatcherException(component.c_str(),
181 sync_point->get_identifier().c_str());
183 if ((*sp_it)->is_emitter(component) && !(*sp_it)->is_watcher(component)) {
184 throw SyncPointCannotReleaseEmitter(component.c_str(), (*sp_it)->get_identifier().c_str());
187 if (sync_point->predecessor_) {
188 release_syncpoint_no_lock(component, sync_point->predecessor_);
193 SyncPointManager::component_watches_any_successor(
const RefPtr<SyncPoint> syncpoint,
194 const std::string component)
const
196 for (std::set<RefPtr<SyncPoint>>::const_iterator it = syncpoint->successors_.begin();
197 it != syncpoint->successors_.end();
199 if ((*it)->get_watchers().count(component)) {