Skip to content

Commit c1739da

Browse files
committed
[CTL] Make CTL API as a variadic functions
Since this commit all the CTL API functions (umfCtlSet/Get/Exec) will be defined as a variadic functions to provide more elastic approach in future development.
1 parent d319917 commit c1739da

File tree

6 files changed

+55
-29
lines changed

6 files changed

+55
-29
lines changed

Diff for: include/umf/base.h

+6-9
Original file line numberDiff line numberDiff line change
@@ -63,29 +63,26 @@ typedef enum umf_ctl_query_type {
6363
///
6464
/// @brief Get value of a specified attribute at the given name.
6565
/// @param name name of an attribute to be retrieved
66-
/// @param ctx pointer to the pool or the provider
67-
/// @param arg [out] pointer to the variable where the value will be stored
66+
/// @param ... number and type of arguments depends on the given name
6867
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
6968
///
70-
umf_result_t umfCtlGet(const char *name, void *ctx, void *arg);
69+
umf_result_t umfCtlGet(const char *name, ...);
7170

7271
///
7372
/// @brief Set value of a specified attribute at the given name.
7473
/// @param name name of an attribute to be set
75-
/// @param ctx pointer to the pool or the provider
76-
/// @param arg [in] pointer to the value that will be set
74+
/// @param ... number and type of arguments depends on the given name
7775
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
7876
///
79-
umf_result_t umfCtlSet(const char *name, void *ctx, void *arg);
77+
umf_result_t umfCtlSet(const char *name, ...);
8078

8179
///
8280
/// @brief Execute callback related with the specified attribute.
8381
/// @param name name of an attribute to be executed
84-
/// @param ctx pointer to the pool or the provider
85-
/// @param arg [in/out] pointer to the value, can be used as an input or output
82+
/// @param ... number and type of arguments depends on the given name
8683
/// @return UMF_RESULT_SUCCESS on success or UMF_RESULT_ERROR_UNKNOWN on failure.
8784
///
88-
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg);
85+
umf_result_t umfCtlExec(const char *name, ...);
8986

9087
#ifdef __cplusplus
9188
}

Diff for: include/umf/memory_pool_ops.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern "C" {
2020
/// @brief Version of the Memory Pool ops structure.
2121
/// NOTE: This is equal to the latest UMF version, in which the ops structure
2222
/// has been modified.
23-
#define UMF_POOL_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11)
23+
#define UMF_POOL_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 12)
2424

2525
///
2626
/// @brief This structure comprises function pointers used by corresponding umfPool*

Diff for: include/umf/memory_provider_ops.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ extern "C" {
1919
/// @brief Version of the Memory Provider ops structure.
2020
/// NOTE: This is equal to the latest UMF version, in which the ops structure
2121
/// has been modified.
22-
#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 11)
22+
#define UMF_PROVIDER_OPS_VERSION_CURRENT UMF_MAKE_VERSION(0, 12)
2323

2424
///
2525
/// @brief This structure comprises optional function pointers used

Diff for: src/ctl/ctl.c

+37-12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <ctype.h>
2222
#include <limits.h>
23+
#include <stdarg.h>
2324
#include <stdint.h>
2425
#include <stdlib.h>
2526
#include <string.h>
@@ -81,30 +82,54 @@ char *Strdup(const char *s) {
8182
return p;
8283
}
8384

84-
umf_result_t umfCtlGet(const char *name, void *ctx, void *arg) {
85-
if (name == NULL || arg == NULL || ctx == NULL) {
86-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
87-
}
85+
umf_result_t umfCtlGet(const char *name, ...) {
86+
assert(name != NULL);
87+
88+
va_list args;
89+
va_start(args, name);
90+
91+
void *ctx = va_arg(args, void *);
92+
void *arg = va_arg(args, void *);
93+
va_end(args);
94+
95+
assert(arg != NULL);
96+
assert(ctx != NULL);
8897
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_READ,
8998
arg)
9099
? UMF_RESULT_ERROR_UNKNOWN
91100
: UMF_RESULT_SUCCESS;
92101
}
93102

94-
umf_result_t umfCtlSet(const char *name, void *ctx, void *arg) {
95-
if (name == NULL || arg == NULL || ctx == NULL) {
96-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
97-
}
103+
umf_result_t umfCtlSet(const char *name, ...) {
104+
assert(name != NULL);
105+
106+
va_list args;
107+
va_start(args, name);
108+
109+
void *ctx = va_arg(args, void *);
110+
void *arg = va_arg(args, void *);
111+
va_end(args);
112+
113+
assert(arg != NULL);
114+
assert(ctx != NULL);
98115
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name, CTL_QUERY_WRITE,
99116
arg)
100117
? UMF_RESULT_ERROR_UNKNOWN
101118
: UMF_RESULT_SUCCESS;
102119
}
103120

104-
umf_result_t umfCtlExec(const char *name, void *ctx, void *arg) {
105-
if (name == NULL || arg == NULL || ctx == NULL) {
106-
return UMF_RESULT_ERROR_INVALID_ARGUMENT;
107-
}
121+
umf_result_t umfCtlExec(const char *name, ...) {
122+
assert(name != NULL);
123+
124+
va_list args;
125+
va_start(args, name);
126+
127+
void *ctx = va_arg(args, void *);
128+
void *arg = va_arg(args, void *);
129+
va_end(args);
130+
131+
assert(arg != NULL);
132+
assert(ctx != NULL);
108133
return ctl_query(NULL, ctx, CTL_QUERY_PROGRAMMATIC, name,
109134
CTL_QUERY_RUNNABLE, arg)
110135
? UMF_RESULT_ERROR_UNKNOWN

Diff for: src/libumf.def

+4-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,6 @@ EXPORTS
119119
umfScalablePoolParamsSetKeepAllMemory
120120
; Added in UMF_0.11
121121
umfCUDAMemoryProviderParamsSetAllocFlags
122-
umfCtlExec
123-
umfCtlGet
124-
umfCtlSet
125122
umfDisjointPoolOps
126123
umfDisjointPoolParamsCreate
127124
umfDisjointPoolParamsDestroy
@@ -139,3 +136,7 @@ EXPORTS
139136
umfFixedMemoryProviderParamsDestroy
140137
umfLevelZeroMemoryProviderParamsSetFreePolicy
141138
umfLevelZeroMemoryProviderParamsSetDeviceOrdinal
139+
; Added in UMF_0.12
140+
umfCtlExec
141+
umfCtlGet
142+
umfCtlSet

Diff for: src/libumf.map

+6-3
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,6 @@ UMF_0.10 {
117117

118118
UMF_0.11 {
119119
umfCUDAMemoryProviderParamsSetAllocFlags;
120-
umfCtlExec;
121-
umfCtlGet;
122-
umfCtlSet;
123120
umfDisjointPoolOps;
124121
umfDisjointPoolParamsCreate;
125122
umfDisjointPoolParamsDestroy;
@@ -138,3 +135,9 @@ UMF_0.11 {
138135
umfLevelZeroMemoryProviderParamsSetFreePolicy;
139136
umfLevelZeroMemoryProviderParamsSetDeviceOrdinal;
140137
} UMF_0.10;
138+
139+
UMF_0.12 {
140+
umfCtlExec;
141+
umfCtlGet;
142+
umfCtlSet;
143+
} UMF_0.11;

0 commit comments

Comments
 (0)