Skip to content

Commit

Permalink
Add interface for accessing CustomReq/Resp data (#1021)
Browse files Browse the repository at this point in the history
* Add interface for accessing CustomReq/Resp data
* Add a setter for the data field.
* Improve CustomRequest/Response interface to clarify the ownership of
CustomData objects.
  • Loading branch information
bwhitchurch authored Jan 8, 2024
1 parent 56ad96c commit 4dff187
Showing 1 changed file with 85 additions and 1 deletion.
86 changes: 85 additions & 1 deletion src/sst/core/interfaces/stdMem.h
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,48 @@ class StandardMem : public SubComponent
return str.str();
}

/**
* Get the CustomData object associated with this request.
* Ownership of the CustomData object is retained by this request.
*/
CustomData& getData() { return *data; }

/**
* Get the CustomData object associated with this request.
* Ownership of the CustomData object is retained by this request.
* The returned data cannot be modified.
*/
const CustomData& getData() const { return *data; }

/**
* Set the CustomData object associated with this request to a new
* value.
* This request takes ownership of the CustomData object.
* The previous CustomData object is deleted.
*/
void setData(CustomData* d)
{
delete data;
data = d;
}

/**
* Reset the CustomData object associated with this request to a new
* value.
* The previous CustomData object is returned and ownership is
* transferred to the caller.
* This request assumes ownership of the passed in CustomData object.
* If no CustomData object is passed in, the data member is set to nullptr.
*/
CustomData* resetData(CustomData* d = nullptr) { return std::exchange(data, d); }

/**
* Obtain the CustomData object associated with this request.
* Ownership of the CustomData object is transferred to the caller.
* The data member of this request is set to nullptr.
*/
CustomData* releaseData() { return resetData(); }

CustomData* data; /* Custom class that holds data for this event */
Addr iPtr; /* Instruction pointer */
uint32_t tid; /* Thread ID */
Expand All @@ -930,7 +972,7 @@ class StandardMem : public SubComponent
{}
CustomResp(CustomReq* req) :
Request(req->getID(), req->getAllFlags()),
data(req->data->makeResponse()),
data(req->getData().makeResponse()),
iPtr(req->iPtr),
tid(req->tid)
{}
Expand All @@ -952,6 +994,48 @@ class StandardMem : public SubComponent
return str.str();
}

/**
* Get the CustomData object associated with this response.
* Ownership of the CustomData object is retained by this response.
*/
CustomData& getData() { return *data; }

/**
* Get the CustomData object associated with this response.
* Ownership of the CustomData object is retained by this response.
* The returned data cannot be modified.
*/
const CustomData& getData() const { return *data; }

/**
* Set the CustomData object associated with this response to a new
* value.
* This response takes ownership of the CustomData object.
* The previous CustomData object is deleted.
*/
void setData(CustomData* d)
{
delete data;
data = d;
}

/**
* Reset the CustomData object associated with this response to a new
* value.
* The previous CustomData object is returned and ownership is
* transferred to the caller.
* This response assumes ownership of the passed in CustomData object.
* If no CustomData object is passed in, the data member is set to nullptr.
*/
CustomData* resetData(CustomData* d = nullptr) { return std::exchange(data, d); }

/**
* Obtain the CustomData object associated with this response.
* Ownership of the CustomData object is transferred to the caller.
* The data member of this response is set to nullptr.
*/
CustomData* releaseData() { return resetData(); }

CustomData* data; /* Custom class that holds data for this event */
Addr iPtr; /* Instruction pointer */
uint32_t tid; /* Thread ID */
Expand Down

0 comments on commit 4dff187

Please sign in to comment.