summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/afb/afb-req-itf.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/include/afb/afb-req-itf.h b/include/afb/afb-req-itf.h
index a8980ffc..a3ff9fe0 100644
--- a/include/afb/afb-req-itf.h
+++ b/include/afb/afb-req-itf.h
@@ -97,6 +97,17 @@ static inline void afb_req_context_set(struct afb_req req, void *value, void (*f
return req.itf->context_set(req.closure, value, free_value);
}
+static inline void *afb_req_context(struct afb_req req, void *(*create_value)(), void (*free_value)(void*))
+{
+ void *result = req.itf->context_get(req.closure);
+ if (result == NULL) {
+ result = create_value();
+ if (result != NULL)
+ req.itf->context_set(req.closure, result, free_value);
+ }
+ return result;
+}
+
static inline void afb_req_context_clear(struct afb_req req)
{
afb_req_context_set(req, NULL, NULL);