Debian Codegraph @

build/future_function_templates/future-functions.c.template

raw
1 {{ header_comment }}
2
3 /*
4 * Define two sets of functions: background functions and future functions.
5
6 * A background function like background_mongoc_cursor_next runs a driver
7 * operation on a thread.
8
9 * A future function like future_mongoc_cursor_next launches the background
10 * operation and returns a future_t that will resolve when the operation
11 * finishes.
12 *
13 * These are used with mock_server_t so you can run the driver on a thread while
14 * controlling the server from the main thread.
15 */
16
17 #include <mongoc/mongoc-topology-private.h>
18
19 #include "mock_server/future-functions.h"
20
21 {% for F in future_functions %}
22 static
23 BSON_THREAD_FUN (background_{{ F.name }}, data)
24 {
25 future_t *future = (future_t *) data;
26 future_value_t return_value;
27
28 return_value.type = future_value_{{ F.ret_type }}_type;
29 {% if F.ret_type == 'void' %}
30 {{ F.name }} ({% for P in F.params %}
31 future_value_get_{{ P.type_name }} (future_get_param (future, {{ loop.index0 }})){% if not loop.last %},{% endif %}{% endfor %});
32 {% else %}
33 future_value_set_{{ F.ret_type }} (
34 &return_value,
35 {{ F.name }} ({% for P in F.params %}
36 future_value_get_{{ P.type_name }} (future_get_param (future, {{ loop.index0 }})){% if not loop.last %},{% endif %}{% endfor %}
37 ));
38 {% endif %}
39 future_resolve (future, return_value);
40
41 BSON_THREAD_RETURN;
42 }
43 {% endfor %}
44 {% for F in future_functions %}
45
46 future_t *
47 {{ F|future_function_name }} ({% for P in F.params %}
48 {{ P.type_name }} {{ P.name }}{% if not loop.last %},{% endif %}{% endfor %})
49 {
50 future_t *future = future_new (future_value_{{ F.ret_type }}_type,
51 {{ F.params | length }});
52 {% for P in F.params %}
53 future_value_set_{{ P.type_name }} (
54 future_get_param (future, {{ loop.index0 }}), {{ P.name }});
55 {% endfor %}
56 future_start (future, background_{{ F.name }});
57 return future;
58 }
59 {%- endfor %}