00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __loaded__ao_scheduler_cpp__
00021 #define __loaded__ao_scheduler_cpp__
00022 using namespace std;
00023 #line 1 "ao-scheduler.c++"
00024 #include <cstdio>
00025 #include <iostream>
00026 #include <string>
00027 #include <stdlib.h>
00028 #include <assert.h>
00029 #include <vector>
00030 #include <queue>
00031 #include <time.h>
00032 #include <pthread.h>
00033 #include "ao-scheduler.h"
00034 #include "ao-pool.h"
00035
00036
00037
00038
00039 static void * startRunner(void* neglect)
00040 {
00041 assert(neglect);
00042 Runnable &info = *(Runnable*)neglect;
00043 #ifdef THREAD_LOGGING
00044 static int threadcount = 0;
00045 int tn=++threadcount;
00046 string name = info.name;
00047 cout << "Start [" << tn << "]: "<< name << endl;
00048 #endif
00049 info.run(true);
00050 #ifdef THREAD_LOGGING
00051 cout << " Stop ["<<tn<<"]: " << name << endl;
00052 threadcount--;
00053 #endif
00054 return NULL;
00055 }
00056
00057 void SpawnWhenActivated::start(Runnable * torun)
00058 {
00059 pthread_t *y = new pthread_t();
00060 int err = pthread_create(y,NULL,startRunner,(void*)torun);
00061 if (err)
00062 {
00063 cerr << "Could not spawn thread , errno = " << err << endl;
00064 cerr.flush();
00065 assert(0);
00066 };
00067 pthread_detach(*y);
00068 }
00069 #endif // __loaded__ao_scheduler_cpp__