00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef SST_CORE_CORE_SHAREDREGION_H
00013 #define SST_CORE_CORE_SHAREDREGION_H
00014
00015 #include <sst/core/sst_types.h>
00016
00017 #include <string>
00018
00019
00020 namespace SST {
00021
00022 class SharedRegion;
00023
00024
00025
00026
00027
00028
00029 class SharedRegionMerger {
00030 public:
00031
00032 class ChangeSet {
00033 private:
00034 friend class boost::serialization::access;
00035 template<class Archive>
00036 void serialize(Archive & ar, const unsigned int version );
00037
00038 public:
00039 ChangeSet() { }
00040 size_t offset;
00041 size_t length;
00042 const uint8_t *data;
00043
00044 ChangeSet(size_t offset, size_t length, const uint8_t *data = NULL) : offset(offset), length(length), data(data) { }
00045
00046 };
00047
00048 virtual ~SharedRegionMerger() { }
00049
00050
00051
00052
00053
00054 virtual bool merge(uint8_t *target, const uint8_t *newData, size_t size);
00055 virtual bool merge(uint8_t *target, size_t size, const std::vector<ChangeSet> &changeSets);
00056 };
00057
00058
00059 class SharedRegionInitializedMerger : public SharedRegionMerger {
00060 uint8_t defVal;
00061 public:
00062 SharedRegionInitializedMerger(uint8_t defaultValue) {
00063 defVal = defaultValue;
00064 }
00065
00066 bool merge(uint8_t *target, const uint8_t *newData, size_t size);
00067
00068 };
00069
00070
00071 class SharedRegionManager {
00072 protected:
00073 friend class SharedRegion;
00074
00075 virtual void modifyRegion(SharedRegion *sr, size_t offset, size_t length, const void *data) = 0;
00076 virtual void* getMemory(SharedRegion* sr) = 0;
00077 virtual const void* getConstPtr(const SharedRegion* sr) const = 0;
00078
00079 public:
00080 virtual SharedRegion* getLocalSharedRegion(const std::string &key, size_t size, uint8_t initByte = 0) = 0;
00081 virtual SharedRegion* getGlobalSharedRegion(const std::string &key, size_t size, SharedRegionMerger *merger = NULL, uint8_t initByte = 0) = 0;
00082
00083 virtual void publishRegion(SharedRegion*) = 0;
00084 virtual bool isRegionReady(const SharedRegion*) = 0;
00085 virtual void shutdownSharedRegion(SharedRegion*) = 0;
00086
00087
00088 virtual void updateState(bool finalize) = 0;
00089 };
00090
00091
00092
00093 class SharedRegion {
00094 private:
00095 SharedRegionManager *manager;
00096 size_t id;
00097 size_t size;
00098
00099 protected:
00100 SharedRegion(SharedRegionManager *manager, size_t id,
00101 size_t size) : manager(manager), id(id),
00102 size(size)
00103 { }
00104
00105 public:
00106
00107 virtual ~SharedRegion()
00108 { }
00109
00110 void shutdown() { manager->shutdownSharedRegion(this); }
00111
00112
00113
00114
00115 size_t getLocalShareID() const { return id; }
00116
00117
00118
00119
00120 size_t getSize() const { return size; }
00121
00122
00123
00124
00125 void publish() { manager->publishRegion(this); }
00126
00127
00128
00129
00130 bool isReady() const { return manager->isRegionReady(this); }
00131
00132
00133
00134
00135
00136 void modifyRegion(size_t offset, size_t length, const void *data)
00137 { manager->modifyRegion(this, offset, length, data); }
00138
00139 template<typename T>
00140 void modifyArray(size_t offset, const T &data)
00141 { manager->modifyRegion(this, offset*sizeof(T), sizeof(T), &data); }
00142
00143
00144
00145
00146
00147 void* getRawPtr() { return manager->getMemory(this); }
00148
00149
00150
00151
00152 template<typename T>
00153 T getPtr() const {
00154 return static_cast<T>(manager->getConstPtr(this));
00155 }
00156 };
00157
00158
00159
00160 }
00161
00162
00163 #endif
00164