00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 #ifndef AMINO_FUTURE_TASK
00022 #define AMINO_FUTURE_TASK
00023 
00024 #include <assert.h>
00025 
00026 #include <amino/condition.h>
00027 #include <amino/mutex.h>
00028 #include <amino/future.h>
00029 #include <amino/thread.h>
00030 
00031 namespace amino{
00032 
00033     class FutureTask:public AbstractFuture, public Runnable{
00034         private:
00035             volatile bool running;
00036             Runnable * fTask;
00037         public:
00044             FutureTask(Runnable * task){
00045                 running = false;
00046                 fTask = task;
00047                 assert(fTask!=NULL);
00048             };
00049 
00050             virtual ~FutureTask(){
00051                 if(running)
00052                     throw logic_error("This task are still running");
00053             }
00054 
00058             virtual void* run(){
00059                 running = true;
00060                 f_result = fTask->run();
00061                 running = false;
00062                 fireEvent();
00063                 return NULL;
00064             }
00065     };
00066 }
00067 #endif