19 #include "threadserver.h"
20 #include "threadexceptions.h"
34 return *this->pinstance;
40 std::list<CThread>::iterator it;
42 if(thread_id.size()==0)
49 for(it=this->thread_list.begin();it!=this->thread_list.end();it++)
57 return (std::list<CThread>::iterator)NULL;
59 return (std::list<CThread>::iterator)NULL;
64 if (CThreadServer::pinstance == NULL)
68 return CThreadServer::pinstance;
74 std::list<CThread>::iterator old_thread;
76 this->access_threads.
enter();
77 if((old_thread=this->
search_thread(thread_id))==(std::list<CThread>::iterator)NULL)
79 new_thread=
new CThread(thread_id);
80 this->thread_list.push_back(*new_thread);
81 this->access_threads.
exit();
85 this->access_threads.
exit();
93 std::list<CThread>::iterator old_thread;
95 this->access_threads.
enter();
96 if((old_thread=this->
search_thread(thread_id))==(std::list<CThread>::iterator)NULL)
98 this->access_threads.
exit();
104 this->thread_list.erase(old_thread);
105 this->access_threads.
exit();
111 std::list<CThread>::iterator thread;
113 this->access_threads.
enter();
114 if((thread=this->
search_thread(thread_id))==(std::list<CThread>::iterator)NULL)
116 this->access_threads.
exit();
122 this->access_threads.
exit();
123 thread->attach(user_thread_function,param);
129 std::list<CThread>::iterator thread;
131 this->access_threads.
enter();
132 if((thread=this->
search_thread(thread_id))==(std::list<CThread>::iterator)NULL)
134 this->access_threads.
exit();
140 this->access_threads.
exit();
147 std::list<CThread>::iterator thread;
149 this->access_threads.
enter();
150 if((thread=this->
search_thread(thread_id))==(std::list<CThread>::iterator)NULL)
152 this->access_threads.
exit();
158 this->access_threads.
exit();
165 std::list<CThread>::iterator thread;
167 this->access_threads.
enter();
168 if((thread=this->
search_thread(thread_id))==(std::list<CThread>::iterator)NULL)
170 this->access_threads.
exit();
176 this->access_threads.
exit();
183 std::list<CThread>::iterator thread;
185 this->access_threads.
enter();
186 if((thread=this->
search_thread(thread_id))==(std::list<CThread>::iterator)NULL)
188 this->access_threads.
exit();
194 this->access_threads.
exit();
199 int CThreadServer::get_thread_state(
const std::string &thread_id)
201 std::list<CThread>::iterator thread;
203 this->access_threads.
enter();
204 if((thread=this->
search_thread(thread_id))==(std::list<CThread>::iterator)NULL)
206 this->access_threads.
exit();
212 this->access_threads.
exit();
213 return thread->get_state();
Thread server exception class.
void create_thread(const std::string &thread_id)
Function to create a new thread.
void start_thread(const std::string &thread_id)
Function to start a thread.
Implementation of a parallel thread of execution.
std::list< CThread >::iterator search_thread(const std::string &thread_id)
Function to search for an specific thread.
void kill_thread(const std::string &thread_id)
Function to immediately terminate a thread.
void end_thread(const std::string &thread_id)
Function to request the termination of a thread.
CThreadServer & operator=(const CThreadServer &object)
assign operator overloading
void delete_thread(const std::string &thread_id)
Function to delete an existing thread.
void attach_thread(const std::string &thread_id, void *(*user_thread_function)(void *param), void *param)
Function to attach a function to a thread.
CThreadServer()
Default constructor.
void exit(void)
function to release the critical section
void enter(void)
function to request access to the critical section
void detach_thread(const std::string &thread_id)
Function to detach a function from a thread.
static CThreadServer * instance(void)
Function to get a reference to the unique instance.