00001
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
00022 friend void * FD::workloop (void *param);
00023
00024 public:
00025
00026
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
00061 pthread_mutex_destroy(&mutex);
00062 }
00063
00064
00065 private:
00066
00068
00069
00070
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 }
00097 #endif