-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add memspace filter functions #743
base: main
Are you sure you want to change the base?
Conversation
12ab322
to
5bd462c
Compare
@@ -39,6 +39,13 @@ umf_result_t umfMemtargetGetType(umf_const_memtarget_handle_t hMemtarget, | |||
umf_result_t umfMemtargetGetCapacity(umf_const_memtarget_handle_t hMemtarget, | |||
size_t *capacity); | |||
|
|||
/// \brief Get ID of the memory target in bytes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"id in bytes" - what does this mean?
@@ -426,3 +426,133 @@ umfMemspaceMemtargetRemove(umf_memspace_handle_t hMemspace, | |||
hMemspace->size--; | |||
return UMF_RESULT_SUCCESS; | |||
} | |||
|
|||
static int MemspaceFilter(umf_memspace_handle_t memspace, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't it be called "umfMemspaceFilter"?
|
||
for (size_t i = 0; i < memspace->size; i++) { | ||
int r = filter(memspace, memspace->nodes[i], args); | ||
if (r < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add comment what it means to got r < 0. Also r->ret. Next - probably we could log here what happened
for (size_t i = 0; i < memspace->size; i++) { | ||
int r = filter(memspace, memspace->nodes[i], args); | ||
if (r < 0) { | ||
return r; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shoulnd't we free the nodesToRemove ptr?
int r = filter(memspace, memspace->nodes[i], args); | ||
if (r < 0) { | ||
return r; | ||
} else if (r == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if r>0? assert?
for (; i < idx; i++) { | ||
ret = umfMemspaceMemtargetRemove(memspace, nodesToRemove[i]); | ||
if (ret != UMF_RESULT_SUCCESS) { | ||
goto re_add; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please add a comment why and what we want to do
int filterById(umf_const_memspace_handle_t memspace, | ||
umf_const_memtarget_handle_t target, void *args) { | ||
if (!memspace && !target && !args) { | ||
return -UMF_RESULT_ERROR_INVALID_ARGUMENT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
negative return? please comment this function
return -UMF_RESULT_ERROR_INVALID_ARGUMENT; | ||
} | ||
|
||
struct filter_by_id_args *filterArgs = args; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use typedef :)
struct filter_by_id_args args = {ids, size}; | ||
int ret = MemspaceFilter(memspace, &filterById, &args); | ||
|
||
return ret < 0 ? -ret : ret; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please comment this :)
size_t size; | ||
}; | ||
|
||
int filterById(umf_const_memspace_handle_t memspace, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be 1000x better if you return only 0 or error code and set item id by output arg
Description
Checklist