2020#include  "base_alloc_global.h" 
2121#include  "coarse.h" 
2222#include  "libumf.h" 
23+ #include  "provider_ctl_stats_type.h" 
2324#include  "utils_common.h" 
2425#include  "utils_concurrency.h" 
2526#include  "utils_log.h" 
@@ -30,6 +31,7 @@ typedef struct fixed_memory_provider_t {
3031    void  * base ;       // base address of memory 
3132    size_t  size ;      // size of the memory region 
3233    coarse_t  * coarse ; // coarse library handle 
34+     ctl_stats_t  stats ;
3335} fixed_memory_provider_t ;
3436
3537// Fixed Memory provider settings struct 
@@ -52,6 +54,17 @@ static __TLS fixed_last_native_error_t TLS_last_native_error;
5254#define  _UMF_FIXED_RESULT_ERROR_PURGE_FORCE_FAILED                              \
5355    (UMF_FIXED_RESULT_ERROR_PURGE_FORCE_FAILED - UMF_FIXED_RESULT_SUCCESS)
5456
57+ #define  CTL_PROVIDER_TYPE  fixed_memory_provider_t
58+ #include  "provider_ctl_stats_impl.h" 
59+ 
60+ struct  ctl  * fixed_memory_ctl_root ;
61+ static  UTIL_ONCE_FLAG  ctl_initialized  =  UTIL_ONCE_FLAG_INIT ;
62+ 
63+ static  void  initialize_fixed_ctl (void ) {
64+     fixed_memory_ctl_root  =  ctl_new ();
65+     CTL_REGISTER_MODULE (fixed_memory_ctl_root , stats );
66+ }
67+ 
5568static  const  char  * Native_error_str [] =  {
5669    [_UMF_FIXED_RESULT_SUCCESS ] =  "success" ,
5770    [_UMF_FIXED_RESULT_ERROR_PURGE_FORCE_FAILED ] =  "force purging failed" };
@@ -153,7 +166,14 @@ static umf_result_t fixed_alloc(void *provider, size_t size, size_t alignment,
153166    fixed_memory_provider_t  * fixed_provider  = 
154167        (fixed_memory_provider_t  * )provider ;
155168
156-     return  coarse_alloc (fixed_provider -> coarse , size , alignment , resultPtr );
169+     umf_result_t  ret  = 
170+         coarse_alloc (fixed_provider -> coarse , size , alignment , resultPtr );
171+ 
172+     if  (ret  ==  UMF_RESULT_SUCCESS ) {
173+         provider_ctl_stats_alloc (fixed_provider , size );
174+     }
175+ 
176+     return  ret ;
157177}
158178
159179static  void  fixed_get_last_native_error (void  * provider , const  char  * * ppMessage ,
@@ -250,7 +270,22 @@ static umf_result_t fixed_allocation_merge(void *provider, void *lowPtr,
250270static  umf_result_t  fixed_free (void  * provider , void  * ptr , size_t  size ) {
251271    fixed_memory_provider_t  * fixed_provider  = 
252272        (fixed_memory_provider_t  * )provider ;
253-     return  coarse_free (fixed_provider -> coarse , ptr , size );
273+ 
274+     umf_result_t  ret  =  coarse_free (fixed_provider -> coarse , ptr , size );
275+ 
276+     if  (ret  ==  UMF_RESULT_SUCCESS ) {
277+         provider_ctl_stats_free (fixed_provider , size );
278+     }
279+ 
280+     return  ret ;
281+ }
282+ 
283+ static  umf_result_t  fixed_ctl (void  * provider , int  operationType ,
284+                               const  char  * name , void  * arg ,
285+                               umf_ctl_query_type_t  query_type ) {
286+     utils_init_once (& ctl_initialized , initialize_fixed_ctl );
287+     return  ctl_query (fixed_memory_ctl_root , provider , operationType , name ,
288+                      query_type , arg );
254289}
255290
256291static  umf_memory_provider_ops_t  UMF_FIXED_MEMORY_PROVIDER_OPS  =  {
@@ -271,7 +306,8 @@ static umf_memory_provider_ops_t UMF_FIXED_MEMORY_PROVIDER_OPS = {
271306    .ipc .get_ipc_handle  =  NULL ,
272307    .ipc .put_ipc_handle  =  NULL ,
273308    .ipc .open_ipc_handle  =  NULL ,
274-     .ipc .close_ipc_handle  =  NULL };
309+     .ipc .close_ipc_handle  =  NULL ,
310+     .ctl  =  fixed_ctl };
275311
276312umf_memory_provider_ops_t  * umfFixedMemoryProviderOps (void ) {
277313    return  & UMF_FIXED_MEMORY_PROVIDER_OPS ;
0 commit comments