/* ######################################################################### # # This file is part of trustyRC. # # trustyRC, fully modular IRC robot # Copyright (C) 2006-2008 Nicoleau Fabien # # trustyRC is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # trustyRC is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with trustyRC. If not, see . # ######################################################################### */ /** @file pthread.h * @brief PThread header file */ #ifndef PTHREAD_H #define PTHREAD_H #include typedef void* (*threadProcess)(void*); /// Stores parameters sended to a thread typedef struct { threadProcess process; void* args; bool* running; bool* finished; } threadParams; /** @brief pthread C++ wrapper * * This class stores pthread management function * to use a pthread as an object */ class PThread { private: /// pthread handle pthread_t* handle; /// running status bool running; /// finished status bool finished; /// threaded function static void* threadStartup(void*); public: /// Constructor PThread(); /// Destructor ~PThread(); /// Prepare and launch a thread bool exec(threadProcess,void*); /// Terminate (cancel) the thread bool terminate(); /// Check if the thread is running bool isRunning(); /// Check if the thread is finished bool isFinished(); /// Join thread void* join(); /// Get thread's handle pthread_t* getHandle(); }; #endif