Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

ThreadedIterator.h

00001 // Copyright (C) 2001 Jean-Marc Valin
00002 
00003 #ifndef _THREADED_ITERATOR_H_
00004 #define _THREADED_ITERATOR_H_
00005 
00012 #include "Iterator.h"
00013 #include <pthread.h>
00014 
00015 namespace FD {
00016 
00017 void * workloop (void *param);
00018 
00019 class ThreadedIterator : public Iterator {
00020 
00021   //the thread workloop
00022   friend void * FD::workloop (void *param);
00023 
00024  public:
00025   
00026   //virtual void setExitStatus() {thread_status = STATUS_STOPPED; this->Network::setExitStatus();}
00027 
00029   ThreadedIterator (std::string nodeName, ParameterSet params);
00030   
00032   virtual ObjectRef getOutput (int output_id, int count);
00033 
00035   void iterator_lock (){pthread_mutex_lock(&mutex);}
00036 
00038   void iterator_unlock(){pthread_mutex_unlock(&mutex);}
00039   
00041   virtual void reset();
00042 
00044   void start_thread();
00045 
00047   void stop_thread();
00048 
00050   virtual void initialize();
00051 
00052 
00054   ~ThreadedIterator () {
00055 
00056     if (status != STATUS_STOPPED) {
00057       stop_thread();
00058     }
00059 
00060     //destroying the mutex
00061     pthread_mutex_destroy(&mutex);
00062   }
00063 
00064   
00065  private:
00066   
00068  /* ThreadedIterator() 
00069     :Iterator (std::string("DUMMY"), new ParameterSet()) {
00070     throw new NodeException (NULL,"The default constructor should not be called from ThreadedIterator",__FILE__,__LINE__);
00071   }*/
00072 
00073   bool  m_in_getOutput;
00074 
00075   static const int STATUS_RUNNING;
00076 
00077   static const int STATUS_STOPPED;
00078   
00079   void* loop(void *param);
00080 
00081   int rate_per_second;
00082 
00083   int internal_pc;
00084 
00085   volatile int thread_status;
00086 
00087 
00088   int status;
00089 
00090   pthread_mutex_t mutex;
00091 
00092   pthread_t work_thread;
00093 
00094 };
00095 
00096 }//namespace FD
00097 #endif

Generated on Wed Oct 5 14:28:56 2005 for FlowDesigner by  doxygen 1.4.4