Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 250365a

Browse files
author
Peter Zion
committedSep 2, 2015
Reduce locking
1 parent 30dc8db commit 250365a

5 files changed

+128
-39
lines changed
 

‎DGGraphImpl.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2427,7 +2427,7 @@ void DGGraphImpl::getDGPortInfo(FabricCore::Variant & portInfo, FabricCore::RTVa
24272427

24282428
if(persistenceContextRT.isValid())
24292429
{
2430-
FabricCore::RTVal rtVal = it->second->getRTVal();
2430+
FabricCore::RTVal rtVal = it->second->getRTVal( FabricSplice::LockType_Context );
24312431
if(rtVal.isValid())
24322432
{
24332433
if(rtVal.isObject())

‎DGPortImpl.cpp

+39-13
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ DGPortImpl::DGPortImpl(
6767
if(!mIsArray && isObject() && doesAutoInitObjects()) {
6868
try
6969
{
70-
FabricCore::RTVal rt = getRTVal();
70+
FabricCore::RTVal rt = getRTVal( FabricCore::LockType_Context );
7171
if(rt.isNullObject())
7272
{
7373
rt = FabricCore::RTVal::Create(*client, mDataType.c_str(), 0, 0);
74-
setRTVal(rt);
74+
setRTVal( FabricCore::LockType_Context, rt );
7575
LoggingImpl::log(("DGPort '"+getName()+"' on Node '"+mGraphName+"' initiated "+mDataType+" reference.").c_str());
7676
}
7777
}
@@ -245,7 +245,12 @@ FabricCore::Variant DGPortImpl::getDefault(std::string * errorOut)
245245
return result;
246246
}
247247

248-
FabricCore::RTVal DGPortImpl::getRTVal(bool evaluate, uint32_t slice, std::string * errorOut)
248+
FabricCore::RTVal DGPortImpl::getRTVal(
249+
FabricCore::LockType lockType,
250+
bool evaluate,
251+
uint32_t slice,
252+
std::string * errorOut
253+
)
249254
{
250255
if(slice > getSliceCount())
251256
{
@@ -265,7 +270,8 @@ FabricCore::RTVal DGPortImpl::getRTVal(bool evaluate, uint32_t slice, std::strin
265270

266271
try
267272
{
268-
FabricCore::RTVal result = mDGNode.getMemberSliceValue(mMember.c_str(), slice);
273+
FabricCore::RTVal result =
274+
mDGNode.getMemberSliceValue_lockType(lockType, mMember.c_str(), slice);
269275
return result;
270276
}
271277
catch(FabricCore::Exception e)
@@ -275,7 +281,12 @@ FabricCore::RTVal DGPortImpl::getRTVal(bool evaluate, uint32_t slice, std::strin
275281
return FabricCore::RTVal();
276282
}
277283

278-
bool DGPortImpl::setRTVal(FabricCore::RTVal value, uint32_t slice, std::string * errorOut)
284+
bool DGPortImpl::setRTVal(
285+
FabricCore::LockType lockType,
286+
FabricCore::RTVal value,
287+
uint32_t slice,
288+
std::string * errorOut
289+
)
279290
{
280291
// if(mMode == Mode_OUT)
281292
// return LoggingImpl::reportError("Cannot set data on an output DGPort.", errorOut);
@@ -284,7 +295,7 @@ bool DGPortImpl::setRTVal(FabricCore::RTVal value, uint32_t slice, std::string *
284295

285296
try
286297
{
287-
mDGNode.setMemberSliceValue(mMember.c_str(), slice, value);
298+
mDGNode.setMemberSliceValue_lockType(lockType, mMember.c_str(), slice, value);
288299
}
289300
catch(FabricCore::Exception e)
290301
{
@@ -333,7 +344,13 @@ uint32_t DGPortImpl::getArrayCount(uint32_t slice, std::string * errorOut)
333344
return 0;
334345
}
335346

336-
bool DGPortImpl::getArrayData(void * buffer, uint32_t bufferSize, uint32_t slice, std::string * errorOut)
347+
bool DGPortImpl::getArrayData(
348+
FabricCore::LockType lockType,
349+
void * buffer,
350+
uint32_t bufferSize,
351+
uint32_t slice,
352+
std::string * errorOut
353+
)
337354
{
338355
if(mMode == Mode_IN)
339356
return LoggingImpl::reportError("Cannot get data on an input DGPort.", errorOut);
@@ -354,7 +371,7 @@ bool DGPortImpl::getArrayData(void * buffer, uint32_t bufferSize, uint32_t slice
354371
uint32_t count = 0;
355372
try
356373
{
357-
count = mDGNode.getMemberSliceArraySize(mMember.c_str(), slice);
374+
count = mDGNode.getMemberSliceArraySize_lockType(lockType, mMember.c_str(), slice);
358375
}
359376
catch(FabricCore::Exception e)
360377
{
@@ -369,7 +386,7 @@ bool DGPortImpl::getArrayData(void * buffer, uint32_t bufferSize, uint32_t slice
369386

370387
try
371388
{
372-
mDGNode.getMemberSliceArrayData(mMember.c_str(), slice, bufferSize, buffer);
389+
mDGNode.getMemberSliceArrayData_lockType(lockType, mMember.c_str(), slice, bufferSize, buffer);
373390
}
374391
catch(FabricCore::Exception e)
375392
{
@@ -379,7 +396,13 @@ bool DGPortImpl::getArrayData(void * buffer, uint32_t bufferSize, uint32_t slice
379396
return true;
380397
}
381398

382-
bool DGPortImpl::setArrayData(void * buffer, uint32_t bufferSize, uint32_t slice, std::string * errorOut)
399+
bool DGPortImpl::setArrayData(
400+
FabricCore::LockType lockType,
401+
void * buffer,
402+
uint32_t bufferSize,
403+
uint32_t slice,
404+
std::string * errorOut
405+
)
383406
{
384407
if(mMode == Mode_OUT)
385408
return LoggingImpl::reportError("Cannot set data on an output DGPort.", errorOut);
@@ -398,9 +421,10 @@ bool DGPortImpl::setArrayData(void * buffer, uint32_t bufferSize, uint32_t slice
398421

399422
try
400423
{
401-
mDGNode.setMemberSliceArraySize(mMember.c_str(), slice, bufferCount);
424+
if ( mDGNode.getMemberSliceArraySize_lockType( lockType, mMember.c_str(), slice ) != bufferCount )
425+
mDGNode.setMemberSliceArraySize( mMember.c_str(), slice, bufferCount );
402426
if(bufferCount > 0)
403-
mDGNode.setMemberSliceArrayData(mMember.c_str(), slice, bufferSize, buffer);
427+
mDGNode.setMemberSliceArrayData_lockType(lockType, mMember.c_str(), slice, bufferSize, buffer);
404428
}
405429
catch(FabricCore::Exception e)
406430
{
@@ -533,7 +557,9 @@ bool DGPortImpl::copyArrayDataFromDGPort(DGPortImplPtr other, uint32_t slice, ui
533557
buffer = malloc(bufferSize);
534558
try
535559
{
536-
other->mDGNode.getMemberSliceArrayData(other->mMember.c_str(), otherSlice, bufferSize, buffer);
560+
other->mDGNode.getMemberSliceArrayData_lockType(
561+
FabricCore::LockType_Context, other->mMember.c_str(), otherSlice, bufferSize, buffer
562+
);
537563
}
538564
catch(FabricCore::Exception e)
539565
{

‎DGPortImpl.h

+32-5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ namespace FabricSpliceImpl
1818

1919
public:
2020

21+
enum Lock
22+
{
23+
Lock_Perform,
24+
Lock_Omit
25+
};
26+
2127
enum Mode
2228
{
2329
Mode_IN,
@@ -113,10 +119,20 @@ namespace FabricSpliceImpl
113119
*/
114120

115121
/// returns the value of a specific slice of this DGPort as a FabricCore::RTVal
116-
FabricCore::RTVal getRTVal(bool evaluate = false, uint32_t slice = 0, std::string * errorOut = NULL);
122+
FabricCore::RTVal getRTVal(
123+
FabricCore::LockType lockType,
124+
bool evaluate = false,
125+
uint32_t slice = 0,
126+
std::string * errorOut = NULL
127+
);
117128

118129
/// sets the value of a specific slice of this DGPort from a FabricCore::RTVal
119-
bool setRTVal(FabricCore::RTVal value, uint32_t slice = 0, std::string * errorOut = NULL);
130+
bool setRTVal(
131+
FabricCore::LockType lockType,
132+
FabricCore::RTVal value,
133+
uint32_t slice = 0,
134+
std::string * errorOut = NULL
135+
);
120136

121137
/*
122138
High Performance IO
@@ -130,12 +146,24 @@ namespace FabricSpliceImpl
130146
/// returns the void* array data of this DGPort.
131147
/// this only works for array DGPorts (isArray() == true)
132148
/// the bufferSize has to match getArrayCount() * getDataSize()
133-
bool getArrayData(void * buffer, uint32_t bufferSize, uint32_t slice = 0, std::string * errorOut = NULL);
149+
bool getArrayData(
150+
FabricCore::LockType lockType,
151+
void * buffer,
152+
uint32_t bufferSize,
153+
uint32_t slice = 0,
154+
std::string * errorOut = NULL
155+
);
134156

135157
/// sets the void* array data of this DGPort.
136158
/// this only works for array DGPorts (isArray() == true)
137159
/// this also sets the array count determined by bufferSize / getDataSize()
138-
bool setArrayData(void * buffer, uint32_t bufferSize, uint32_t slice = 0, std::string * errorOut = NULL);
160+
bool setArrayData(
161+
FabricCore::LockType lockType,
162+
void * buffer,
163+
uint32_t bufferSize,
164+
uint32_t slice = 0,
165+
std::string * errorOut = NULL
166+
);
139167

140168
/// gets the void* slice array data of this DGPort.
141169
/// this only works for non-array DGPorts (isArray() == false)
@@ -170,7 +198,6 @@ namespace FabricSpliceImpl
170198
// gets a dictionary of all options
171199
FabricCore::Variant getAllOptions();
172200

173-
174201
private:
175202
DGPortImpl(DGGraphImplPtr thisGraph, const std::string & name, const std::string & member, FabricCore::DGNode dgNode, const std::string & dgNodeName, Mode mode, uint32_t dataSize, bool shallow, bool autoInitObjects);
176203

‎FabricSplice.cpp

+31-8
Original file line numberDiff line numberDiff line change
@@ -2165,19 +2165,30 @@ void FECS_DGPort_getDefault(FECS_DGPortRef ref, FabricCore::Variant & result)
21652165
FECS_CATCH_VOID
21662166
}
21672167

2168-
void FECS_DGPort_getRTVal(FECS_DGPortRef ref, bool evaluate, unsigned int slice, FabricCore::RTVal & result)
2168+
void FECS_DGPort_getRTVal(
2169+
FECS_LockType lockType,
2170+
FECS_DGPortRef ref,
2171+
bool evaluate,
2172+
unsigned int slice,
2173+
FabricCore::RTVal & result
2174+
)
21692175
{
21702176
FECS_TRY_CLEARERROR
21712177
GETSMARTPTRVOID(DGPortImplPtr, port)
2172-
result = port->getRTVal(evaluate, slice);
2178+
result = port->getRTVal(lockType, evaluate, slice);
21732179
FECS_CATCH_VOID
21742180
}
21752181

2176-
bool FECS_DGPort_setRTVal(FECS_DGPortRef ref, const FabricCore::RTVal & value, unsigned int slice)
2182+
bool FECS_DGPort_setRTVal(
2183+
FECS_LockType lockType,
2184+
FECS_DGPortRef ref,
2185+
const FabricCore::RTVal & value,
2186+
unsigned int slice
2187+
)
21772188
{
21782189
FECS_TRY_CLEARERROR
21792190
GETSMARTPTR(DGPortImplPtr, port, false)
2180-
return port->setRTVal(value, slice);
2191+
return port->setRTVal(lockType, value, slice);
21812192
FECS_CATCH(false);
21822193
}
21832194

@@ -2189,19 +2200,31 @@ unsigned int FECS_DGPort_getArrayCount(FECS_DGPortRef ref, unsigned int slice)
21892200
FECS_CATCH(0);
21902201
}
21912202

2192-
bool FECS_DGPort_getArrayData(FECS_DGPortRef ref, void * buffer, unsigned int bufferSize, unsigned int slice)
2203+
bool FECS_DGPort_getArrayData(
2204+
FECS_LockType lockType,
2205+
FECS_DGPortRef ref,
2206+
void * buffer,
2207+
unsigned int bufferSize,
2208+
unsigned int slice
2209+
)
21932210
{
21942211
FECS_TRY_CLEARERROR
21952212
GETSMARTPTR(DGPortImplPtr, port, false)
2196-
return port->getArrayData(buffer, bufferSize, slice);
2213+
return port->getArrayData(lockType, buffer, bufferSize, slice);
21972214
FECS_CATCH(false);
21982215
}
21992216

2200-
bool FECS_DGPort_setArrayData(FECS_DGPortRef ref, void * buffer, unsigned int bufferSize, unsigned int slice)
2217+
bool FECS_DGPort_setArrayData(
2218+
FECS_LockType lockType,
2219+
FECS_DGPortRef ref,
2220+
void * buffer,
2221+
unsigned int bufferSize,
2222+
unsigned int slice
2223+
)
22012224
{
22022225
FECS_TRY_CLEARERROR
22032226
GETSMARTPTR(DGPortImplPtr, port, false)
2204-
return port->setArrayData(buffer, bufferSize, slice);
2227+
return port->setArrayData(lockType, buffer, bufferSize, slice);
22052228
FECS_CATCH(false);
22062229
}
22072230

‎FabricSplice.h

+25-12
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,10 @@ enum FECS_DGPort_Mode
17501750
FECS_DGPort_Mode_IO = 2
17511751
};
17521752

1753+
typedef FEC_LockType FECS_LockType;
1754+
#define FECS_LockType_Context FEC_LockType_Context
1755+
#define FECS_LockType_None FEC_LockType_None
1756+
17531757
// C functions
17541758
//=====================================================
17551759
FECS_DECL void FECS_Initialize();
@@ -1992,11 +1996,11 @@ FECS_DECL bool FECS_DGPort_setVariant(FECS_DGPortRef ref, const FabricCore::Vari
19921996
FECS_DECL char * FECS_DGPort_getJSON(FECS_DGPortRef ref, unsigned int slice);
19931997
FECS_DECL bool FECS_DGPort_setJSON(FECS_DGPortRef ref, const char * json, unsigned int slice);
19941998
FECS_DECL void FECS_DGPort_getDefault(FECS_DGPortRef ref, FabricCore::Variant & result);
1995-
FECS_DECL void FECS_DGPort_getRTVal(FECS_DGPortRef ref, bool evaluate, unsigned int slice, FabricCore::RTVal & result);
1996-
FECS_DECL bool FECS_DGPort_setRTVal(FECS_DGPortRef ref, const FabricCore::RTVal & value, unsigned int slice);
1999+
FECS_DECL void FECS_DGPort_getRTVal(FECS_LockType lockType, FECS_DGPortRef ref, bool evaluate, unsigned int slice, FabricCore::RTVal & result);
2000+
FECS_DECL bool FECS_DGPort_setRTVal(FECS_LockType lockType, FECS_DGPortRef ref, const FabricCore::RTVal & value, unsigned int slice);
19972001
FECS_DECL unsigned int FECS_DGPort_getArrayCount(FECS_DGPortRef ref, unsigned int slice);
1998-
FECS_DECL bool FECS_DGPort_getArrayData(FECS_DGPortRef ref, void * buffer, unsigned int bufferSize, unsigned int slice);
1999-
FECS_DECL bool FECS_DGPort_setArrayData(FECS_DGPortRef ref, void * buffer, unsigned int bufferSize, unsigned int slice);
2002+
FECS_DECL bool FECS_DGPort_getArrayData(FECS_LockType lockType, FECS_DGPortRef ref, void * buffer, unsigned int bufferSize, unsigned int slice);
2003+
FECS_DECL bool FECS_DGPort_setArrayData(FECS_LockType lockType, FECS_DGPortRef ref, void * buffer, unsigned int bufferSize, unsigned int slice);
20002004
FECS_DECL bool FECS_DGPort_getAllSlicesData(FECS_DGPortRef ref, void * buffer, unsigned int bufferSize);
20012005
FECS_DECL bool FECS_DGPort_setAllSlicesData(FECS_DGPortRef ref, void * buffer, unsigned int bufferSize);
20022006
FECS_DECL bool FECS_DGPort_copyArrayDataFromPort(FECS_DGPortRef ref, FECS_DGPortRef otherRef, unsigned int slice, unsigned int otherSlice);
@@ -2047,6 +2051,10 @@ namespace FabricSplice
20472051
Port_Mode_IO = FECS_DGPort_Mode_IO
20482052
};
20492053

2054+
typedef FECS_LockType LockType;
2055+
static const LockType LockType_Context = FEC_LockType_Context;
2056+
static const LockType LockType_None = FEC_LockType_None;
2057+
20502058
class Exception
20512059
{
20522060
protected:
@@ -3795,18 +3803,18 @@ namespace FabricSplice
37953803
}
37963804

37973805
// returns the value of a specific slice of this DGPort as a FabricCore::RTVal
3798-
FabricCore::RTVal getRTVal(bool evaluate = false, uint32_t slice = 0)
3806+
FabricCore::RTVal getRTVal(LockType lockType, bool evaluate = false, uint32_t slice = 0)
37993807
{
38003808
FabricCore::RTVal result;
3801-
FECS_DGPort_getRTVal(mRef, evaluate, slice, result);
3809+
FECS_DGPort_getRTVal(lockType, mRef, evaluate, slice, result);
38023810
Exception::MaybeThrow();
38033811
return result;
38043812
}
38053813

38063814
// sets the value of a specific slice of this DGPort from a FabricCore::RTVal
3807-
bool setRTVal(FabricCore::RTVal value, uint32_t slice = 0)
3815+
bool setRTVal(LockType lockType, FabricCore::RTVal value, uint32_t slice = 0)
38083816
{
3809-
bool result = FECS_DGPort_setRTVal(mRef, value, slice);
3817+
bool result = FECS_DGPort_setRTVal(lockType, mRef, value, slice);
38103818
Exception::MaybeThrow();
38113819
return result;
38123820
}
@@ -3857,19 +3865,24 @@ namespace FabricSplice
38573865
// returns the void* array data of this DGPort.
38583866
// this only works for array Ports (isArray() == true)
38593867
// the bufferSize has to match getArrayCount() * getDataSize()
3860-
bool getArrayData(void * buffer, unsigned int bufferSize, unsigned int slice = 0)
3868+
bool getArrayData(
3869+
LockType lockType,
3870+
void * buffer,
3871+
unsigned int bufferSize,
3872+
unsigned int slice = 0
3873+
)
38613874
{
3862-
bool result = FECS_DGPort_getArrayData(mRef, buffer, bufferSize, slice);
3875+
bool result = FECS_DGPort_getArrayData(lockType, mRef, buffer, bufferSize, slice);
38633876
Exception::MaybeThrow();
38643877
return result;
38653878
}
38663879

38673880
// sets the void* array data of this DGPort.
38683881
// this only works for array Ports (isArray() == true)
38693882
// this also sets the array count determined by bufferSize / getDataSize()
3870-
bool setArrayData(void * buffer, unsigned int bufferSize, unsigned int slice = 0)
3883+
bool setArrayData(LockType lockType, void * buffer, unsigned int bufferSize, unsigned int slice = 0)
38713884
{
3872-
bool result = FECS_DGPort_setArrayData(mRef, buffer, bufferSize, slice);
3885+
bool result = FECS_DGPort_setArrayData(lockType, mRef, buffer, bufferSize, slice);
38733886
Exception::MaybeThrow();
38743887
return result;
38753888
}

0 commit comments

Comments
 (0)
Please sign in to comment.