Skip to content

Commit

Permalink
dashboard object reference counting
Browse files Browse the repository at this point in the history
  • Loading branch information
mvladic committed May 25, 2024
1 parent 7f3eeb1 commit d79e775
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/eez/core/value.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ struct ArrayValue;
struct ArrayElementValue;
struct BlobRef;

#if defined(EEZ_DASHBOARD_API)
namespace flow {
extern void dashboardObjectValueIncRef(int json);
extern void dashboardObjectValueDecRef(int json);
}
#endif

////////////////////////////////////////////////////////////////////////////////

struct Value {
Expand Down Expand Up @@ -238,6 +245,12 @@ struct Value {
}
}
}*/

#if defined(EEZ_DASHBOARD_API)
if (type == VALUE_TYPE_JSON || type == VALUE_TYPE_STREAM) {
flow::dashboardObjectValueDecRef(int32Value);;
}
#endif
}

Value& operator = (const Value &value) {
Expand Down Expand Up @@ -266,6 +279,12 @@ struct Value {
pValueValue->refValue->refCounter++;
}
}*/

#if defined(EEZ_DASHBOARD_API)
if (type == VALUE_TYPE_JSON || type == VALUE_TYPE_STREAM) {
flow::dashboardObjectValueIncRef(value.int32Value);;
}
#endif
}

return *this;
Expand Down
14 changes: 14 additions & 0 deletions src/eez/flow/dashboard_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ Value operationJsonClone(int json) {
return result;
}

void dashboardObjectValueIncRef(int json) {
EM_ASM({
dashboardObjectValueIncRef($0, $1);
}, g_wasmModuleId, json);
}

void dashboardObjectValueDecRef(int json) {
EM_ASM({
dashboardObjectValueDecRef($0, $1);
}, g_wasmModuleId, json);
}

void onObjectArrayValueFree(ArrayValue *arrayValue) {
EM_ASM({
onObjectArrayValueFree($0, $1);
Expand Down Expand Up @@ -157,6 +169,7 @@ EM_PORT_API(Value *) createArrayValue(int arraySize, int arrayType) {
}

EM_PORT_API(Value *) createStreamValue(int value) {
dashboardObjectValueIncRef(value);
auto pValue = ObjectAllocator<Value>::allocate(0x53a2e660);
*pValue = Value(value, VALUE_TYPE_STREAM);
return pValue;
Expand All @@ -175,6 +188,7 @@ EM_PORT_API(Value *) createBlobValue(const uint8_t *buffer, uint32_t bufferLen)
}

EM_PORT_API(Value *) createJsonValue(int value) {
dashboardObjectValueIncRef(value);
auto pValue = ObjectAllocator<Value>::allocate(0x734f514c);
*pValue = Value(value, VALUE_TYPE_JSON);
return pValue;
Expand Down
3 changes: 3 additions & 0 deletions src/eez/flow/dashboard_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ int operationJsonSet(int json, const char *property, const Value *valuePtr);
int operationJsonArrayLength(int json);
Value operationJsonClone(int json);

void dashboardObjectValueIncRef(int json);
void dashboardObjectValueDecRef(int json);

void onObjectArrayValueFree(ArrayValue *arrayValue);

} // flow
Expand Down

0 comments on commit d79e775

Please sign in to comment.