14 : data_(std::move(data_plane))
26 NamedWorkerThreads::iterator found = threads_.find(name);
28 if (found != threads_.end())
36 for (NamedWorkerThreads::iterator i = threads_.begin(); i != threads_.end();
45 NamedWorkerThreads::iterator found = threads_.find(name);
47 if (found != threads_.end())
55 for (NamedWorkerThreads::iterator i = threads_.begin(); i != threads_.end();
65 if (name !=
"" && thread != 0)
67 std::unique_ptr<WorkerThread> worker(
76 (threads_[name] = std::move(worker))->run();
78 else if (thread != 0 && name ==
"")
83 "Threader::run: named thread has an empty name. Deleting new thread.");
86 "Threader::run: named thread has an empty name. Deleting new thread.");
91 "Threader::run: named thread has an empty name.");
94 "Threader::run: named thread has an empty name.");
101 const std::string& name, jobject thread,
bool paused)
103 if (name !=
"" && thread != 0)
111 run(name, new_thread, paused);
117 double hertz,
const std::string& name, jobject thread,
bool paused)
119 if (name !=
"" && thread != 0)
126 run(hertz, name, new_thread, paused);
135 if (name !=
"" && thread != 0)
137 std::unique_ptr<WorkerThread> worker(
138 new WorkerThread(name, thread, control_, data_, hertz));
146 (threads_[name] = std::move(worker))->run();
148 else if (thread != 0 && name ==
"")
153 "Threader::run: named thread has an empty name. Deleting new thread.");
156 "Threader::run: named thread has an empty name. Deleting new thread.");
161 "Threader::run: named thread has an empty name.");
164 "Threader::run: named thread has an empty name.");
171 data_ = std::move(data_plane);
176 NamedWorkerThreads::iterator found = threads_.find(name);
178 if (found != threads_.end())
186 for (NamedWorkerThreads::iterator i = threads_.begin(); i != threads_.end();
199 #ifndef _MADARA_NO_KARL_
200 NamedWorkerThreads::iterator found = threads_.find(name);
202 if (found != threads_.end())
204 std::string condition = found->second->finished_.get_name();
206 result = this->control_.wait(condition, ws).is_true();
210 threads_.erase(found);
222 #ifndef _MADARA_NO_KARL_
223 std::stringstream condition;
225 NamedWorkerThreads::iterator i = threads_.begin();
228 if (i != threads_.end())
230 condition << i->second->finished_.get_name();
235 for (; i != threads_.end(); ++i)
238 condition << i->second->finished_.get_name();
241 if (threads_.size() > 0)
243 result = this->control_.wait(condition.str(), ws).is_true();
260 #ifndef _MADARA_NO_KARL_
261 NamedWorkerThreads::iterator found = threads_.find(name);
263 if (found != threads_.end())
266 condition += found->second->running_.get_name();
268 result = this->control_.wait(condition, ws).is_true();
280 #ifndef _MADARA_NO_KARL_
281 std::stringstream condition;
283 NamedWorkerThreads::iterator i = threads_.begin();
286 if (i != threads_.end())
289 i->second->running_.get_name();
294 for (; i != threads_.end(); ++i)
297 condition << i->second->running_.get_name();
300 if (threads_.size() > 0)
302 result = this->control_.wait(condition.str(), ws).is_true();
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
An exception for general thread-related errors.
This class provides a distributed knowledge base to users.
Abstract base class for implementing threads.
madara::knowledge::containers::Integer paused
thread safe paused flag that may be set by the Threader
A facade for a user-defined Java thread class.
static JavaThread * create(jobject obj)
Creates a JavaThread.
void pause(void)
Requests all threads to pause.
void terminate(void)
Requests all threads to terminate.
void run(const std::string &name, BaseThread *thread, bool paused=false)
Starts a new thread and executes the provided user thread once.
bool wait_for_paused(const std::string &name, const knowledge::WaitSettings &ws=knowledge::WaitSettings())
Wait for a specific thread to reach paused state.
Threader()
Default constructor.
void resume(void)
Requests all threads to resume (unpause)
bool wait(const std::string &name, const knowledge::WaitSettings &ws=knowledge::WaitSettings())
Wait for a specific thread to complete.
void set_data_plane(knowledge::KnowledgeBase &data_plane)
Sets the data plane for new threads.
A thread that executes BaseThread logic.
T get(const KnowledgeRecord &kr)
Get the value of a KnowlegeRecord.
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger
Encapsulates settings for a wait statement.