00001 #ifndef _CACHE_H_
00002 #define _CACHE_H_
00003
00004 #include <pthread.h>
00005 #include "constants.h"
00006 #include "prod_cons.h"
00007 #include "TaskIdList.h"
00008 #include "DataSpaceId.h"
00009 #include "Task.h"
00010 #include "FilterDev.h"
00011
00012 #define KEY_DSI
00013 #define VAL_VOID
00014 #include "hash.h"
00015 #undef VAL_VOID
00016 #undef KEY_DSI
00017
00018 #define KEY_INT
00019 #define VAL_INT
00020 #include "hash.h"
00021 #undef VAL_INT
00022 #undef KEY_INT
00023
00024
00025 typedef struct {
00026 int workId;
00027 int taskId;
00028 Task *task;
00029 } FinishedTask;
00030
00031
00032
00033 typedef struct {
00034 int IAmTaskCreator;
00035 int useTasks;
00036 int forwardTaskMsgs;
00037 HashDSIVoid *tasks;
00038 TaskIdList *terminatedTasks;
00039 HashIntInt *runningTasks;
00040 int currentWork;
00041 int currentTask;
00042 prod_cons_t *taskBuffer;
00043 pthread_t writeThreadDescriptor;
00044 char *finishedTasksDir;
00045 RecoverCallback_t * recoverCallback;
00046 } Cache;
00047
00048
00049 void initCache ();
00050 void destroyCache ();
00051
00052 void setCreator();
00053 void cacheSetUseTasks();
00054 int cacheGetUseTasks();
00055 void cacheSetForwardTaskMsgs(int forward);
00056 int cacheGetForwardTaskMsgs();
00057
00058 int cacheCreateTask(int taskId, int * deps, int depSize, char * metadata, int metaSize);
00059 int cacheEndTask(int taskId);
00060
00061 int cachePutData(char *key, void * data, int dataSz);
00062 void *cacheGetData(int taskId, char *key, int *dataSz);
00063 int cacheRemoveData(char *key);
00064
00065 TaskIdList *getFinishedTasks();
00066 int cacheRecoverTasks(TaskIdList *tasks);
00067 int cacheGetRunningTasks( int * numTasks, int ** taskList );
00068 int *cacheGetFinishedTasks(int *numTasks);
00069
00070 void cacheSetCurrentWork(int work);
00071 int cacheGetCurrentWork();
00072 int cacheSetCurrentTask(int task);
00073 int cacheGetCurrentTask();
00074
00075 int writeTaskState(FILE * outputFile, Cache * cache);
00076 int readTaskState(FILE * inputFile);
00077 int *cacheGetTaskDeps(int taskId, int *depsSz);
00078
00079 int defaultRecoveryCallback(int newTaskId,int *newTaskDep,int depSize,char *metadata,int metaSize);
00080 int cacheRegisterRecoverCallback( RecoverCallback_t * callback );
00081
00082
00083 #ifdef _TEST_CACHE_
00084
00085 Cache *___getCache();
00086 #endif
00087
00088
00089 #endif