diff options
| author | Chia-I Wu <olvaffe@gmail.com> | 2014-08-05 10:17:50 +0800 |
|---|---|---|
| committer | Chia-I Wu <olvaffe@gmail.com> | 2014-08-06 11:30:11 +0800 |
| commit | 29eedf8bd64a47c713c448657eafd6e72ef1e9af (patch) | |
| tree | 381c061958d71c42619794acf0073aee15a43a7f | |
| parent | 529ab129909d928a349cb00b4cb30af9169b737e (diff) | |
| download | usermoji-29eedf8bd64a47c713c448657eafd6e72ef1e9af.tar.xz | |
icd: assign each allocator a unique id
It can be used to determine if an object is allocated by the current
allocator.
| -rw-r--r-- | icd/common/icd.c | 18 | ||||
| -rw-r--r-- | icd/common/icd.h | 3 |
2 files changed, 16 insertions, 5 deletions
diff --git a/icd/common/icd.c b/icd/common/icd.c index 7dd8103a..0d279f8b 100644 --- a/icd/common/icd.c +++ b/icd/common/icd.c @@ -50,7 +50,7 @@ struct icd { bool break_on_warning; XGL_ALLOC_CALLBACKS alloc_callbacks; - bool alloc_callbacks_initialized; + int init_count; }; static XGL_VOID *default_alloc(XGL_VOID *user_data, @@ -217,9 +217,14 @@ ICD_EXPORT XGL_RESULT XGLAPI xglDbgSetGlobalOption(XGL_DBG_GLOBAL_OPTION dbgOpti return res; } -XGL_RESULT icd_set_alloc_callbacks(const XGL_ALLOC_CALLBACKS *alloc_cb) +XGL_RESULT icd_set_allocator(const XGL_ALLOC_CALLBACKS *alloc_cb) { - if (icd.alloc_callbacks_initialized) { + if (icd.init_count) { + /* + * The spec says: Changing the callbacks on subsequent calls to + * xglInitAndEnumerateGpus() causes it to fail with + * XGL_ERROR_INVALID_POINTER error. + */ return (memcmp(&icd.alloc_callbacks, alloc_cb, sizeof(*alloc_cb))) ? XGL_ERROR_INVALID_POINTER : XGL_SUCCESS; } @@ -227,11 +232,16 @@ XGL_RESULT icd_set_alloc_callbacks(const XGL_ALLOC_CALLBACKS *alloc_cb) if (alloc_cb) icd.alloc_callbacks = *alloc_cb; - icd.alloc_callbacks_initialized = true; + icd.init_count++; return XGL_SUCCESS; } +int icd_get_allocator_id(void) +{ + return icd.init_count; +} + void *icd_alloc(XGL_SIZE size, XGL_SIZE alignment, XGL_SYSTEM_ALLOC_TYPE type) { diff --git a/icd/common/icd.h b/icd/common/icd.h index 323d9561..00916e5b 100644 --- a/icd/common/icd.h +++ b/icd/common/icd.h @@ -63,7 +63,8 @@ void icd_log(XGL_DBG_MSG_TYPE msg_type, void icd_clear_msg_callbacks(void); -XGL_RESULT icd_set_alloc_callbacks(const XGL_ALLOC_CALLBACKS *alloc_cb); +XGL_RESULT icd_set_allocator(const XGL_ALLOC_CALLBACKS *alloc_cb); +int icd_get_allocator_id(void); void *icd_alloc(XGL_SIZE size, XGL_SIZE alignment, XGL_SYSTEM_ALLOC_TYPE type); |
