-
Notifications
You must be signed in to change notification settings - Fork 0
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
move providers to UMF #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,15 +28,26 @@ typedef struct umf_memory_provider_t *umf_memory_provider_handle_t; | |
/// \return UMF_RESULT_SUCCESS on success or appropriate error code on failure. | ||
/// | ||
enum umf_result_t | ||
umfMemoryProviderCreate(struct umf_memory_provider_ops_t *ops, void *params, | ||
umf_memory_provider_handle_t *hProvider); | ||
umfMemoryProviderCreate(const struct umf_memory_provider_ops_t *ops, | ||
void *params, umf_memory_provider_handle_t *hProvider); | ||
|
||
/// | ||
/// \brief Destroys memory provider. | ||
/// \param hPool handle to the memory provider | ||
/// | ||
void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider); | ||
|
||
// TODO comment | ||
enum umf_result_t | ||
umfMemoryProviderRegister(struct umf_memory_provider_ops_t *ops); | ||
|
||
enum umf_result_t | ||
umfMemoryProvidersRegistryGet(struct umf_memory_provider_ops_t *providers, | ||
size_t *numProviders); | ||
|
||
const struct umf_memory_provider_ops_t * | ||
umfMemoryProvidersRegistryGetOps(char *name); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it be better to return |
||
|
||
/// | ||
/// \brief Allocates size bytes of uninitialized storage from memory provider | ||
/// with specified alignment. | ||
|
@@ -110,7 +121,7 @@ umfMemoryProviderGetMinPageSize(umf_memory_provider_handle_t hProvider, | |
|
||
/// | ||
/// \brief Discard physical pages within the virtual memory mapping associated at given addr and size. | ||
/// This call is asynchronous and may delay puring the pages indefinitely. | ||
/// This call is asynchronous and may delay purging the pages indefinitely. | ||
/// \param hProvider handle to the memory provider | ||
/// \param ptr beginning of the virtual memory range | ||
/// \param size size of the virtual memory range | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,22 +8,30 @@ | |
* | ||
*/ | ||
|
||
#include "memory_provider_internal.h" | ||
#include <umf/memory_provider.h> | ||
|
||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
#include <algorithm> | ||
#include <cstring> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "umf/memory_provider.h" | ||
|
||
#include "memory_provider_internal.h" | ||
|
||
struct umf_memory_provider_t { | ||
struct umf_memory_provider_ops_t ops; | ||
void *provider_priv; | ||
}; | ||
|
||
std::vector<struct umf_memory_provider_ops_t> globalProviders; | ||
|
||
enum umf_result_t | ||
umfMemoryProviderCreate(struct umf_memory_provider_ops_t *ops, void *params, | ||
umf_memory_provider_handle_t *hProvider) { | ||
umfMemoryProviderCreate(const struct umf_memory_provider_ops_t *ops, | ||
void *params, umf_memory_provider_handle_t *hProvider) { | ||
umf_memory_provider_handle_t provider = | ||
malloc(sizeof(struct umf_memory_provider_t)); | ||
(umf_memory_provider_t *)malloc(sizeof(struct umf_memory_provider_t)); | ||
if (!provider) { | ||
return UMF_RESULT_ERROR_OUT_OF_HOST_MEMORY; | ||
} | ||
|
@@ -46,6 +54,42 @@ umfMemoryProviderCreate(struct umf_memory_provider_ops_t *ops, void *params, | |
return UMF_RESULT_SUCCESS; | ||
} | ||
|
||
enum umf_result_t umfMemoryProviderRegister(umf_memory_provider_ops_t *ops) { | ||
|
||
// TODO check if this provider isn't already registered | ||
globalProviders.push_back(*ops); | ||
|
||
return UMF_RESULT_SUCCESS; | ||
} | ||
|
||
enum umf_result_t | ||
umfMemoryProvidersRegistryGet(umf_memory_provider_ops_t *providers, | ||
size_t *numProviders) { | ||
|
||
if (providers == NULL) { | ||
*numProviders = globalProviders.size(); | ||
} else { | ||
memcpy(providers, globalProviders.data(), | ||
sizeof(umf_memory_provider_ops_t) * *numProviders); | ||
} | ||
|
||
return UMF_RESULT_SUCCESS; | ||
} | ||
|
||
// TODO rename ;) | ||
const umf_memory_provider_ops_t *umfMemoryProvidersRegistryGetOps(char *name) { | ||
auto it = std::find_if( | ||
std::begin(globalProviders), std::end(globalProviders), | ||
[&](auto &ops) { return std::strcmp(ops.get_name(NULL), name) == 0; }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A general comment: until now we assumed that all function pointers in |
||
|
||
if (it != globalProviders.end()) { | ||
return &(*it); | ||
} | ||
|
||
// else | ||
return NULL; | ||
} | ||
|
||
void umfMemoryProviderDestroy(umf_memory_provider_handle_t hProvider) { | ||
hProvider->ops.finalize(hProvider->provider_priv); | ||
free(hProvider); | ||
|
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.
where it is used?