00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "fennel/common/CommonPreamble.h"
00025 #include "fennel/exec/DynamicParam.h"
00026 #include "fennel/tuple/TupleAccessor.h"
00027 #include "fennel/tuple/TupleData.h"
00028 #include "fennel/tuple/StandardTypeDescriptor.h"
00029
00030 FENNEL_BEGIN_CPPFILE("$Id: //open/dev/fennel/exec/DynamicParam.cpp#12 $");
00031
00032 DynamicParam::DynamicParam(
00033 TupleAttributeDescriptor const &descInit,
00034 bool isCounterInit)
00035 : desc(descInit) , isCounter(isCounterInit)
00036 {
00037 pBuffer.reset(new FixedBuffer[desc.cbStorage]);
00038 }
00039
00040 void DynamicParamManager::createParam(
00041 DynamicParamId dynamicParamId,
00042 const TupleAttributeDescriptor &attrDesc,
00043 bool failIfExists)
00044 {
00045 StrictMutexGuard mutexGuard(mutex);
00046
00047 SharedDynamicParam param(new DynamicParam(attrDesc));
00048 createParam(dynamicParamId, param, failIfExists);
00049 }
00050
00051 void DynamicParamManager::createParam(
00052 DynamicParamId dynamicParamId,
00053 SharedDynamicParam param,
00054 bool failIfExists)
00055 {
00056 ParamMapConstIter pExisting = paramMap.find(dynamicParamId);
00057 if (pExisting != paramMap.end()) {
00058 permAssert(!failIfExists);
00059 assert(param->desc == pExisting->second->getDesc());
00060 return;
00061 }
00062 paramMap.insert(ParamMap::value_type(dynamicParamId, param));
00063 }
00064
00065 void DynamicParamManager::createCounterParam(
00066 DynamicParamId dynamicParamId,
00067 bool failIfExists)
00068 {
00069 StrictMutexGuard mutexGuard(mutex);
00070
00071 StandardTypeDescriptorFactory stdTypeFactory;
00072 TupleAttributeDescriptor attrDesc(
00073 stdTypeFactory.newDataType(STANDARD_TYPE_INT_64));
00074 SharedDynamicParam param(new DynamicParam(attrDesc, true));
00075 createParam(dynamicParamId, param, failIfExists);
00076
00077
00078 PBuffer buf = param->pBuffer.get();
00079 int64_t *pCounter = reinterpret_cast<int64_t *>(buf);
00080 *pCounter = 0;
00081 param->datum.pData = buf;
00082 param->datum.cbData = sizeof(int64_t);
00083 }
00084
00085 void DynamicParamManager::deleteParam(DynamicParamId dynamicParamId)
00086 {
00087 StrictMutexGuard mutexGuard(mutex);
00088
00089 assert(paramMap.find(dynamicParamId) != paramMap.end());
00090 paramMap.erase(dynamicParamId);
00091 assert(paramMap.find(dynamicParamId) == paramMap.end());
00092 }
00093
00094 void DynamicParamManager::writeParam(
00095 DynamicParamId dynamicParamId, const TupleDatum &src)
00096 {
00097 StrictMutexGuard mutexGuard(mutex);
00098
00099 DynamicParam ¶m = getParamInternal(dynamicParamId);
00100 if (src.pData) {
00101 assert(src.cbData <= param.getDesc().cbStorage);
00102 }
00103 param.datum.pData = param.pBuffer.get();
00104 param.datum.memCopyFrom(src);
00105 }
00106
00107 DynamicParam const &DynamicParamManager::getParam(
00108 DynamicParamId dynamicParamId)
00109 {
00110 StrictMutexGuard mutexGuard(mutex);
00111 return getParamInternal(dynamicParamId);
00112 }
00113
00114 DynamicParam &DynamicParamManager::getParamInternal(
00115 DynamicParamId dynamicParamId)
00116 {
00117 ParamMapConstIter pExisting = paramMap.find(dynamicParamId);
00118 assert(pExisting != paramMap.end());
00119 return *(pExisting->second.get());
00120 }
00121
00122 void DynamicParamManager::readParam(
00123 DynamicParamId dynamicParamId, TupleDatum &dest)
00124 {
00125 StrictMutexGuard mutexGuard(mutex);
00126 dest.memCopyFrom(getParamInternal(dynamicParamId).datum);
00127 }
00128
00129 void DynamicParamManager::incrementCounterParam(DynamicParamId dynamicParamId)
00130 {
00131 StrictMutexGuard mutexGuard(mutex);
00132
00133 DynamicParam ¶m = getParamInternal(dynamicParamId);
00134 assert(param.isCounter);
00135 int64_t *pCounter = reinterpret_cast<int64_t *>(param.pBuffer.get());
00136 (*pCounter)++;
00137 }
00138
00139 void DynamicParamManager::decrementCounterParam(DynamicParamId dynamicParamId)
00140 {
00141 StrictMutexGuard mutexGuard(mutex);
00142
00143 DynamicParam ¶m = getParamInternal(dynamicParamId);
00144 assert(param.isCounter);
00145 int64_t *pCounter = reinterpret_cast<int64_t *>(param.pBuffer.get());
00146 (*pCounter)--;
00147 }
00148
00149 void DynamicParamManager::deleteAllParams()
00150 {
00151 StrictMutexGuard mutexGuard(mutex);
00152 paramMap.erase(paramMap.begin(), paramMap.end());
00153 }
00154
00155 FENNEL_END_CPPFILE("$Id: //open/dev/fennel/exec/DynamicParam.cpp#12 $");
00156
00157