Skip to content

Commit 5d3d05f

Browse files
committed
don't copy future_t before getting params
1 parent f919677 commit 5d3d05f

File tree

6 files changed

+43
-137
lines changed

6 files changed

+43
-137
lines changed

build/future_function_templates/future-functions.c.template

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,19 @@ static void *
2323
background_{{ F.name }} (void *data)
2424
{
2525
future_t *future = (future_t *) data;
26-
27-
/* copy the future so we can unlock it while calling
28-
* {{ F.name }}
29-
*/
30-
future_t *copy = future_new_copy (future);
3126
future_value_t return_value;
3227

3328
return_value.type = future_value_{{ F.ret_type }}_type;
3429
{% if F.ret_type == 'void' %}
3530
{{ F.name }} ({% for P in F.params %}
36-
future_value_get_{{ P.type_name }} (future_get_param(copy, {{ loop.index0 }})){% if not loop.last %},{% endif %}{% endfor %});
31+
future_value_get_{{ P.type_name }} (future_get_param (future, {{ loop.index0 }})){% if not loop.last %},{% endif %}{% endfor %});
3732
{% else %}
3833
future_value_set_{{ F.ret_type }} (
3934
&return_value,
40-
{{ F.name }} ({% for P in F.params %}
41-
future_value_get_{{ P.type_name }} (future_get_param(copy, {{ loop.index0 }})){% if not loop.last %},{% endif %}{% endfor %}
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 %}
4237
));
4338
{% endif %}
44-
future_destroy (copy);
4539
future_resolve (future, return_value);
4640

4741
return NULL;

build/future_function_templates/future.c.template

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,6 @@ future_get_param (future_t *future, int i)
5151
return &future->argv[i];
5252
}
5353

54-
future_t *
55-
future_new_copy (future_t *future)
56-
{
57-
future_t *copy;
58-
59-
mongoc_mutex_lock (&future->mutex);
60-
copy = future_new (future->return_value.type, future->argc);
61-
copy->return_value = future->return_value;
62-
memcpy (copy->argv, future->argv, future->argc * sizeof(future_value_t));
63-
mongoc_mutex_unlock (&future->mutex);
64-
65-
return copy;
66-
}
67-
68-
6954
void
7055
future_start (future_t *future,
7156
void *(*start_routine)(void *))

build/future_function_templates/future.h.template

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ typedef struct
2121

2222
future_t *future_new (future_value_type_t return_type, int argc);
2323

24-
future_t *future_new_copy (future_t *future);
25-
2624
future_value_t *future_get_param (future_t *future, int i);
2725

2826
void future_start (future_t *future,

tests/mock_server/future-functions.c

Lines changed: 40 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,18 @@ static void *
2929
background_mongoc_bulk_operation_execute (void *data)
3030
{
3131
future_t *future = (future_t *) data;
32-
33-
/* copy the future so we can unlock it while calling
34-
* mongoc_bulk_operation_execute
35-
*/
36-
future_t *copy = future_new_copy (future);
3732
future_value_t return_value;
3833

3934
return_value.type = future_value_uint32_t_type;
4035

4136
future_value_set_uint32_t (
4237
&return_value,
43-
mongoc_bulk_operation_execute (
44-
future_value_get_mongoc_bulk_operation_ptr (future_get_param(copy, 0)),
45-
future_value_get_bson_ptr (future_get_param(copy, 1)),
46-
future_value_get_bson_error_ptr (future_get_param(copy, 2))
38+
mongoc_bulk_operation_execute (
39+
future_value_get_mongoc_bulk_operation_ptr (future_get_param (future, 0)),
40+
future_value_get_bson_ptr (future_get_param (future, 1)),
41+
future_value_get_bson_error_ptr (future_get_param (future, 2))
4742
));
4843

49-
future_destroy (copy);
5044
future_resolve (future, return_value);
5145

5246
return NULL;
@@ -56,27 +50,21 @@ static void *
5650
background_mongoc_client_command_simple (void *data)
5751
{
5852
future_t *future = (future_t *) data;
59-
60-
/* copy the future so we can unlock it while calling
61-
* mongoc_client_command_simple
62-
*/
63-
future_t *copy = future_new_copy (future);
6453
future_value_t return_value;
6554

6655
return_value.type = future_value_bool_type;
6756

6857
future_value_set_bool (
6958
&return_value,
70-
mongoc_client_command_simple (
71-
future_value_get_mongoc_client_ptr (future_get_param(copy, 0)),
72-
future_value_get_const_char_ptr (future_get_param(copy, 1)),
73-
future_value_get_const_bson_ptr (future_get_param(copy, 2)),
74-
future_value_get_const_mongoc_read_prefs_ptr (future_get_param(copy, 3)),
75-
future_value_get_bson_ptr (future_get_param(copy, 4)),
76-
future_value_get_bson_error_ptr (future_get_param(copy, 5))
59+
mongoc_client_command_simple (
60+
future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
61+
future_value_get_const_char_ptr (future_get_param (future, 1)),
62+
future_value_get_const_bson_ptr (future_get_param (future, 2)),
63+
future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 3)),
64+
future_value_get_bson_ptr (future_get_param (future, 4)),
65+
future_value_get_bson_error_ptr (future_get_param (future, 5))
7766
));
7867

79-
future_destroy (copy);
8068
future_resolve (future, return_value);
8169

8270
return NULL;
@@ -86,26 +74,20 @@ static void *
8674
background_mongoc_collection_aggregate (void *data)
8775
{
8876
future_t *future = (future_t *) data;
89-
90-
/* copy the future so we can unlock it while calling
91-
* mongoc_collection_aggregate
92-
*/
93-
future_t *copy = future_new_copy (future);
9477
future_value_t return_value;
9578

9679
return_value.type = future_value_mongoc_cursor_ptr_type;
9780

9881
future_value_set_mongoc_cursor_ptr (
9982
&return_value,
100-
mongoc_collection_aggregate (
101-
future_value_get_mongoc_collection_ptr (future_get_param(copy, 0)),
102-
future_value_get_mongoc_query_flags_t (future_get_param(copy, 1)),
103-
future_value_get_const_bson_ptr (future_get_param(copy, 2)),
104-
future_value_get_const_bson_ptr (future_get_param(copy, 3)),
105-
future_value_get_const_mongoc_read_prefs_ptr (future_get_param(copy, 4))
83+
mongoc_collection_aggregate (
84+
future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
85+
future_value_get_mongoc_query_flags_t (future_get_param (future, 1)),
86+
future_value_get_const_bson_ptr (future_get_param (future, 2)),
87+
future_value_get_const_bson_ptr (future_get_param (future, 3)),
88+
future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 4))
10689
));
10790

108-
future_destroy (copy);
10991
future_resolve (future, return_value);
11092

11193
return NULL;
@@ -115,27 +97,21 @@ static void *
11597
background_mongoc_collection_insert_bulk (void *data)
11698
{
11799
future_t *future = (future_t *) data;
118-
119-
/* copy the future so we can unlock it while calling
120-
* mongoc_collection_insert_bulk
121-
*/
122-
future_t *copy = future_new_copy (future);
123100
future_value_t return_value;
124101

125102
return_value.type = future_value_bool_type;
126103

127104
future_value_set_bool (
128105
&return_value,
129-
mongoc_collection_insert_bulk (
130-
future_value_get_mongoc_collection_ptr (future_get_param(copy, 0)),
131-
future_value_get_mongoc_insert_flags_t (future_get_param(copy, 1)),
132-
future_value_get_const_bson_ptr_ptr (future_get_param(copy, 2)),
133-
future_value_get_uint32_t (future_get_param(copy, 3)),
134-
future_value_get_const_mongoc_write_concern_ptr (future_get_param(copy, 4)),
135-
future_value_get_bson_error_ptr (future_get_param(copy, 5))
106+
mongoc_collection_insert_bulk (
107+
future_value_get_mongoc_collection_ptr (future_get_param (future, 0)),
108+
future_value_get_mongoc_insert_flags_t (future_get_param (future, 1)),
109+
future_value_get_const_bson_ptr_ptr (future_get_param (future, 2)),
110+
future_value_get_uint32_t (future_get_param (future, 3)),
111+
future_value_get_const_mongoc_write_concern_ptr (future_get_param (future, 4)),
112+
future_value_get_bson_error_ptr (future_get_param (future, 5))
136113
));
137114

138-
future_destroy (copy);
139115
future_resolve (future, return_value);
140116

141117
return NULL;
@@ -145,19 +121,13 @@ static void *
145121
background_mongoc_cursor_destroy (void *data)
146122
{
147123
future_t *future = (future_t *) data;
148-
149-
/* copy the future so we can unlock it while calling
150-
* mongoc_cursor_destroy
151-
*/
152-
future_t *copy = future_new_copy (future);
153124
future_value_t return_value;
154125

155126
return_value.type = future_value_void_type;
156127

157128
mongoc_cursor_destroy (
158-
future_value_get_mongoc_cursor_ptr (future_get_param(copy, 0)));
129+
future_value_get_mongoc_cursor_ptr (future_get_param (future, 0)));
159130

160-
future_destroy (copy);
161131
future_resolve (future, return_value);
162132

163133
return NULL;
@@ -167,23 +137,17 @@ static void *
167137
background_mongoc_cursor_next (void *data)
168138
{
169139
future_t *future = (future_t *) data;
170-
171-
/* copy the future so we can unlock it while calling
172-
* mongoc_cursor_next
173-
*/
174-
future_t *copy = future_new_copy (future);
175140
future_value_t return_value;
176141

177142
return_value.type = future_value_bool_type;
178143

179144
future_value_set_bool (
180145
&return_value,
181-
mongoc_cursor_next (
182-
future_value_get_mongoc_cursor_ptr (future_get_param(copy, 0)),
183-
future_value_get_const_bson_ptr_ptr (future_get_param(copy, 1))
146+
mongoc_cursor_next (
147+
future_value_get_mongoc_cursor_ptr (future_get_param (future, 0)),
148+
future_value_get_const_bson_ptr_ptr (future_get_param (future, 1))
184149
));
185150

186-
future_destroy (copy);
187151
future_resolve (future, return_value);
188152

189153
return NULL;
@@ -193,23 +157,17 @@ static void *
193157
background_mongoc_client_get_database_names (void *data)
194158
{
195159
future_t *future = (future_t *) data;
196-
197-
/* copy the future so we can unlock it while calling
198-
* mongoc_client_get_database_names
199-
*/
200-
future_t *copy = future_new_copy (future);
201160
future_value_t return_value;
202161

203162
return_value.type = future_value_char_ptr_ptr_type;
204163

205164
future_value_set_char_ptr_ptr (
206165
&return_value,
207-
mongoc_client_get_database_names (
208-
future_value_get_mongoc_client_ptr (future_get_param(copy, 0)),
209-
future_value_get_bson_error_ptr (future_get_param(copy, 1))
166+
mongoc_client_get_database_names (
167+
future_value_get_mongoc_client_ptr (future_get_param (future, 0)),
168+
future_value_get_bson_error_ptr (future_get_param (future, 1))
210169
));
211170

212-
future_destroy (copy);
213171
future_resolve (future, return_value);
214172

215173
return NULL;
@@ -219,23 +177,17 @@ static void *
219177
background_mongoc_database_get_collection_names (void *data)
220178
{
221179
future_t *future = (future_t *) data;
222-
223-
/* copy the future so we can unlock it while calling
224-
* mongoc_database_get_collection_names
225-
*/
226-
future_t *copy = future_new_copy (future);
227180
future_value_t return_value;
228181

229182
return_value.type = future_value_char_ptr_ptr_type;
230183

231184
future_value_set_char_ptr_ptr (
232185
&return_value,
233-
mongoc_database_get_collection_names (
234-
future_value_get_mongoc_database_ptr (future_get_param(copy, 0)),
235-
future_value_get_bson_error_ptr (future_get_param(copy, 1))
186+
mongoc_database_get_collection_names (
187+
future_value_get_mongoc_database_ptr (future_get_param (future, 0)),
188+
future_value_get_bson_error_ptr (future_get_param (future, 1))
236189
));
237190

238-
future_destroy (copy);
239191
future_resolve (future, return_value);
240192

241193
return NULL;
@@ -245,26 +197,20 @@ static void *
245197
background_mongoc_topology_select (void *data)
246198
{
247199
future_t *future = (future_t *) data;
248-
249-
/* copy the future so we can unlock it while calling
250-
* mongoc_topology_select
251-
*/
252-
future_t *copy = future_new_copy (future);
253200
future_value_t return_value;
254201

255202
return_value.type = future_value_mongoc_server_description_ptr_type;
256203

257204
future_value_set_mongoc_server_description_ptr (
258205
&return_value,
259-
mongoc_topology_select (
260-
future_value_get_mongoc_topology_ptr (future_get_param(copy, 0)),
261-
future_value_get_mongoc_ss_optype_t (future_get_param(copy, 1)),
262-
future_value_get_const_mongoc_read_prefs_ptr (future_get_param(copy, 2)),
263-
future_value_get_int64_t (future_get_param(copy, 3)),
264-
future_value_get_bson_error_ptr (future_get_param(copy, 4))
206+
mongoc_topology_select (
207+
future_value_get_mongoc_topology_ptr (future_get_param (future, 0)),
208+
future_value_get_mongoc_ss_optype_t (future_get_param (future, 1)),
209+
future_value_get_const_mongoc_read_prefs_ptr (future_get_param (future, 2)),
210+
future_value_get_int64_t (future_get_param (future, 3)),
211+
future_value_get_bson_error_ptr (future_get_param (future, 4))
265212
));
266213

267-
future_destroy (copy);
268214
future_resolve (future, return_value);
269215

270216
return NULL;

tests/mock_server/future.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -288,21 +288,6 @@ future_get_param (future_t *future, int i)
288288
return &future->argv[i];
289289
}
290290

291-
future_t *
292-
future_new_copy (future_t *future)
293-
{
294-
future_t *copy;
295-
296-
mongoc_mutex_lock (&future->mutex);
297-
copy = future_new (future->return_value.type, future->argc);
298-
copy->return_value = future->return_value;
299-
memcpy (copy->argv, future->argv, future->argc * sizeof(future_value_t));
300-
mongoc_mutex_unlock (&future->mutex);
301-
302-
return copy;
303-
}
304-
305-
306291
void
307292
future_start (future_t *future,
308293
void *(*start_routine)(void *))

tests/mock_server/future.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ typedef struct
2727

2828
future_t *future_new (future_value_type_t return_type, int argc);
2929

30-
future_t *future_new_copy (future_t *future);
31-
3230
future_value_t *future_get_param (future_t *future, int i);
3331

3432
void future_start (future_t *future,

0 commit comments

Comments
 (0)