"Fossies" - the Fresh Open Source Software Archive

Member "postal-0.76/thread.h" (10 Apr 2008, 1505 Bytes) of package /linux/privat/postal-0.76.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "thread.h" see the Fossies "Dox" file reference documentation.

    1 #ifndef THREAD_H
    2 #define THREAD_H
    3 
    4 #include "port.h"
    5 
    6 #include <sys/poll.h>
    7 #include <pthread.h>
    8 
    9 class Thread;
   10 
   11 typedef void *PVOID;
   12 
   13 typedef struct
   14 {
   15   Thread *f;
   16   PVOID param;
   17   int threadNum;
   18 } THREAD_DATA;
   19 
   20 class Thread
   21 {
   22 protected:
   23   // Virtual function that is called when the thread is started.
   24   // The parameter is the pointer that is passed first to the go() function
   25   virtual int action(PVOID param) = 0;
   26 
   27   // constructor for main thread class
   28   Thread();
   29 
   30   // constructor for children.
   31   Thread(int threadNum, const Thread *parent);
   32   virtual ~Thread();
   33 
   34   void go(PVOID param, int num); // creates all threads
   35 
   36   int getNumThreads() const { return m_numThreads; }
   37 
   38   // Virtual function to construct a new class.
   39   // the following comment has the implementation
   40   // return new class(threadNum, this);
   41   virtual Thread *newThread(int threadNum) = 0;
   42 
   43   // set the return value of the thread, probably not needed
   44   void setRetVal(int rc);
   45 
   46 protected:
   47   int getThreadNum() const { return m_threadNum; }
   48   int Read(PVOID buf, int size, int timeout = 60);
   49   int Write(PVOID buf, int size, int timeout = 60);
   50 
   51 protected:
   52   int m_read;
   53   int m_write;
   54 private:
   55 
   56   int m_threadNum;
   57 
   58   pollfd m_readPoll;
   59   pollfd m_writePoll;
   60   int m_parentRead;
   61   int m_parentWrite;
   62   int m_childRead;
   63   int m_childWrite;
   64   int m_numThreads;
   65   int *m_retVal;
   66   pthread_t *m_thread_info;
   67 
   68   Thread(const Thread &f);
   69   Thread & operator =(const Thread &f);
   70 
   71 
   72   friend PVOID thread_func(PVOID param);
   73 };
   74 
   75 #endif
   76