thread.h
Go to the documentation of this file.
/* -*- C++ -*-
* OO encapsulation of Posix threads
*
* Copyright (C) 2003--2013 Enrico Zini <enrico@debian.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef WIBBLE_SYS_THREAD_H
#define WIBBLE_SYS_THREAD_H
#include <wibble/sys/macros.h>
#include <wibble/exception.h>
#ifdef POSIX
#include <pthread.h>
#include <unistd.h>
#endif
#ifdef _WIN32
#include <windows.h>
#include <process.h>
#endif
#include <signal.h>
namespace wibble {
namespace sys {
void sleep( int secs );
void usleep( int usecs );
class Thread
{
protected:
#ifdef POSIX
pthread_t thread;
#endif
#ifdef _WIN32
void *_result;
unsigned int thread;
HANDLE hThread;
#endif
virtual const char* threadTag() { return "generic"; }
virtual void* main() = 0;
#ifdef POSIX
static void* Starter(void* parm);
#endif
#ifdef _WIN32
static unsigned __stdcall Starter(void* parm);
#endif
void testcancel();
public:
virtual ~Thread() {}
void start();
void startDetached();
void* join();
void detach();
void cancel();
void kill(int signal);
};
}
}
// vim:set ts=4 sw=4:
#endif
wibble::sys::Thread
Encapsulates a thread.
Definition: thread.h:84
wibble::sys::Thread::threadTag
virtual const char * threadTag()
Short tag describing this thread, used in error messages and identification.
Definition: thread.h:100
wibble::sys::Thread::cancel
void cancel()
Send a cancellation request to the thread.
Definition: thread.cpp:133
wibble::sys::Thread::testcancel
void testcancel()
Callback function used to start the thread.
Definition: thread.cpp:63
wibble::sys::Thread::~Thread
virtual ~Thread()
Definition: thread.h:120
wibble::sys::Thread::startDetached
void startDetached()
Start the thread in the detached state.
Definition: thread.cpp:87
wibble::sys::Thread::join
void * join()
Join the thread.
Definition: thread.cpp:100
wibble::sys::Thread::start
void start()
Start the thread.
Definition: thread.cpp:70
wibble::sys::Thread::kill
void kill(int signal)
Sent a signal to the thread.
Definition: thread.cpp:142
wibble::sys::Thread::main
virtual void * main()=0
Main thread function, executed in the new thread after creation.
wibble::sys::Thread::detach
void detach()
Put the thread in the detached state.
Definition: thread.cpp:124
exception.h
macros.h
wibble::sys::sleep
void sleep(int secs)
Portable version of sleep.
Definition: thread.cpp:31
wibble::sys::usleep
void usleep(int usecs)
Portable version of usleep.
Definition: thread.cpp:39
wibble
Definition: amorph.h:17
process.h
signal.h