General IRI utilities
threadserver.h
1 // Copyright (C) 2009-2010 Institut de Robòtica i Informàtica Industrial, CSIC-UPC.
2 // Author Sergi Hernandez (shernand@iri.upc.edu)
3 // All rights reserved.
4 //
5 // This file is part of iriutils
6 // iriutils is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef _THREAD_SERVER
20 #define _THREAD_SERVER
21 
22 #include <list>
23 #include "thread.h"
24 #include "mutex.h"
25 
58 {
59  private:
68  static CThreadServer* pinstance;
77  std::list<CThread> thread_list;
79 
83  CMutex access_threads;
84  protected:
96  CThreadServer();
108  CThreadServer(const CThreadServer& object);
120  CThreadServer& operator = (const CThreadServer& object);
144  std::list<CThread>::iterator search_thread(const std::string& thread_id);
145  public:
161  static CThreadServer* instance(void);
162  // Thread handler functions
188  void create_thread(const std::string& thread_id);
189 
211  void delete_thread(const std::string& thread_id);
212 
239  void attach_thread(const std::string& thread_id,void *(*user_thread_function)(void *param),void *param);
240 
258  void start_thread(const std::string& thread_id);
259 
277  void end_thread(const std::string& thread_id);
278 
297  void kill_thread(const std::string& thread_id);
298 
316  void detach_thread(const std::string& thread_id);
317 
322  int get_thread_state(const std::string &thread_id);
323 };
324 
325 #endif
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.
std::list< CThread >::iterator search_thread(const std::string &thread_id)
Function to search for an specific thread.
Implementation of a mutual exclusion mechanism.
Definition: mutex.h:46
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 detach_thread(const std::string &thread_id)
Function to detach a function from a thread.
Global thread server.
Definition: threadserver.h:57
static CThreadServer * instance(void)
Function to get a reference to the unique instance.