82 lines
1.6 KiB
C++
82 lines
1.6 KiB
C++
//
|
|
// Linux Daemon
|
|
//
|
|
|
|
/* prevent multiple inclusions */
|
|
#ifndef __Thread__
|
|
#define __Thread__
|
|
|
|
/* includes *****************************************************************/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/types.h>
|
|
#include <errno.h>
|
|
#include <memory.h>
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
#include "netlib.h"
|
|
|
|
/* defines ******************************************************************/
|
|
|
|
/* macros *******************************************************************/
|
|
|
|
/* structs & typedefs *******************************************************/
|
|
|
|
/* c class definitions ******************************************************/
|
|
|
|
class Thread {
|
|
// public data
|
|
public:
|
|
void *m_arg;
|
|
|
|
// protected data
|
|
protected:
|
|
pthread_t m_thread;
|
|
pthread_attr_t m_attr;
|
|
|
|
// private data
|
|
private:
|
|
bool m_join;
|
|
|
|
// public methods
|
|
public:
|
|
// constructors
|
|
Thread();
|
|
|
|
// destructor
|
|
virtual ~Thread();
|
|
|
|
Thread( const Thread& );
|
|
const Thread& operator=( const Thread& );
|
|
|
|
// public methods
|
|
void Init(void);
|
|
int Start( void *arg = NULL, bool detach = false );
|
|
int Stop( void );
|
|
int Join( void **pptr = NULL );
|
|
|
|
pthread_t GetTid(void) {return m_thread;};
|
|
|
|
// virtual functions
|
|
virtual bool Prep(void);
|
|
virtual void *Run(void *) = 0; // {return NULL;};
|
|
|
|
// exceptions
|
|
class ThreadException
|
|
{
|
|
char *toString(void) { return strerror(errno); };
|
|
};
|
|
|
|
// static methods to override
|
|
|
|
// private methods
|
|
private:
|
|
// signal catchers (do not override)
|
|
};
|
|
|
|
#endif
|