Skip to content

Commit f38a42d

Browse files
authored
Merge pull request #1434 from lplewa/va_args
Va args
2 parents ebdb14f + 2a49448 commit f38a42d

23 files changed

+860
-493
lines changed

benchmark/benchmark_umf.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ struct provider_interface {
4545
if (state.thread_index() != 0) {
4646
return;
4747
}
48-
umfCtlExec("umf.provider.by_handle.stats.peak_memory.reset", provider,
49-
NULL, 0);
48+
umfCtlExec("umf.provider.by_handle.{}.stats.peak_memory.reset", NULL, 0,
49+
provider);
5050
}
5151

5252
void postBench([[maybe_unused]] ::benchmark::State &state) {
@@ -55,8 +55,8 @@ struct provider_interface {
5555
}
5656
size_t arg;
5757
umf_result_t ret =
58-
umfCtlGet("umf.provider.by_handle.stats.allocated_memory", provider,
59-
&arg, sizeof(arg));
58+
umfCtlGet("umf.provider.by_handle.{}.stats.allocated_memory", &arg,
59+
sizeof(arg), provider);
6060
if (ret == UMF_RESULT_SUCCESS) {
6161
state.counters["provider_memory_allocated"] =
6262
static_cast<double>(arg);

include/umf/base.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,16 @@ typedef enum umf_ctl_query_type {
5656
CTL_QUERY_READ,
5757
CTL_QUERY_WRITE,
5858
CTL_QUERY_RUNNABLE,
59-
CTL_QUERY_SUBTREE,
60-
61-
MAX_CTL_QUERY_TYPE
6259
} umf_ctl_query_type_t;
6360

61+
typedef enum ctl_query_source {
62+
CTL_UNKNOWN_QUERY_SOURCE,
63+
/* query executed directly from the program */
64+
CTL_QUERY_PROGRAMMATIC,
65+
/* query executed from the config file */
66+
CTL_QUERY_CONFIG_INPUT
67+
} umf_ctl_query_source_t;
68+
6469
#ifdef __cplusplus
6570
}
6671
#endif

include/umf/experimental/ctl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@ extern "C" {
1919
///
2020
/// @brief Get value of a specified attribute at the given name.
2121
/// @param name name of an attribute to be retrieved
22-
/// @param ctx pointer to the pool or the provider
2322
/// @param arg [out] pointer to the variable where the value will be stored
2423
/// @param size size of the value, depends on the context
24+
/// @param ... additional arguments that can be passed to the callback
2525
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
2626
///
27-
umf_result_t umfCtlGet(const char *name, void *ctx, void *arg, size_t size);
27+
umf_result_t umfCtlGet(const char *name, void *arg, size_t size, ...);
2828

2929
///
3030
/// @brief Set value of a specified attribute at the given name.
3131
/// @param name name of an attribute to be set
32-
/// @param ctx pointer to the pool or the provider, NULL for the 'default' path
3332
/// @param arg [in] pointer to the value that will be set
3433
/// @param size [in] size of the value, depends on the context
34+
/// @param ... additional arguments that can be passed to the callback
3535
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
3636
///
37-
umf_result_t umfCtlSet(const char *name, void *ctx, void *arg, size_t size);
37+
umf_result_t umfCtlSet(const char *name, void *arg, size_t size, ...);
3838

3939
///
4040
/// @brief Execute callback related with the specified attribute.
4141
/// @param name name of an attribute to be executed
42-
/// @param ctx pointer to the pool or the provider
4342
/// @param arg [in/out] pointer to the value, can be used as an input or output
4443
/// @param size [in] size of the value, depends on the context
44+
/// @param ... additional arguments that can be passed to the callback
4545
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
4646
///
47-
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg, size_t size);
47+
umf_result_t umfCtlExec(const char *name, void *arg, size_t size, ...);
4848

4949
#ifdef __cplusplus
5050
}

include/umf/memory_pool_ops.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef UMF_MEMORY_POOL_OPS_H
1111
#define UMF_MEMORY_POOL_OPS_H 1
1212

13+
#include <stdarg.h>
14+
1315
#include <umf/base.h>
1416
#include <umf/memory_provider.h>
1517

@@ -153,17 +155,18 @@ typedef struct umf_memory_pool_ops_t {
153155
/// on the memory pool.
154156
///
155157
/// @param pool handle to the memory pool.
156-
/// @param operationType type of the operation to be performed.
158+
/// @param source source of the ctl operation.
157159
/// @param name name associated with the operation.
158160
/// @param arg argument for the operation.
159161
/// @param size size of the argument [optional - check name requirements]
160162
/// @param queryType type of the query to be performed.
163+
/// @param args variable arguments for the operation.
161164
///
162165
/// @return umf_result_t result of the control operation.
163166
///
164-
umf_result_t (*ext_ctl)(void *hPool, int operationType, const char *name,
165-
void *arg, size_t size,
166-
umf_ctl_query_type_t queryType);
167+
umf_result_t (*ext_ctl)(void *hPool, umf_ctl_query_source_t source,
168+
const char *name, void *arg, size_t size,
169+
umf_ctl_query_type_t queryType, va_list args);
167170

168171
} umf_memory_pool_ops_t;
169172

include/umf/memory_provider_ops.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef UMF_MEMORY_PROVIDER_OPS_H
1111
#define UMF_MEMORY_PROVIDER_OPS_H 1
1212

13+
#include <stdarg.h>
14+
1315
#include <umf/base.h>
1416

1517
#ifdef __cplusplus
@@ -263,17 +265,18 @@ typedef struct umf_memory_provider_ops_t {
263265
/// Backward compatibility is not guaranteed.
264266
///
265267
/// @param provider handle to the memory provider.
266-
/// @param operationType type of the operation to be performed.
268+
/// @param source source of the ctl operation.
267269
/// @param name name associated with the operation.
268270
/// @param arg argument for the operation.
269271
/// @param size size of the argument [optional - check name requirements]
270272
/// @param queryType type of the query to be performed.
273+
/// @param args variable arguments for the operation.
271274
///
272275
/// @return umf_result_t result of the control operation.
273276
///
274-
umf_result_t (*ext_ctl)(void *provider, int operationType, const char *name,
275-
void *arg, size_t size,
276-
umf_ctl_query_type_t queryType);
277+
umf_result_t (*ext_ctl)(void *provider, umf_ctl_query_source_t source,
278+
const char *name, void *arg, size_t size,
279+
umf_ctl_query_type_t queryType, va_list args);
277280

278281
} umf_memory_provider_ops_t;
279282

0 commit comments

Comments
 (0)