2 ctdb request id handling code
4 Copyright (C) Amitay Isaacs 2015
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
24 #include "lib/util/idtree.h"
27 struct reqid_context
{
28 struct idr_context
*idr
;
32 int reqid_init(TALLOC_CTX
*mem_ctx
, int start_id
,
33 struct reqid_context
**result
)
35 struct reqid_context
*reqid_ctx
;
37 reqid_ctx
= talloc_zero(mem_ctx
, struct reqid_context
);
38 if (reqid_ctx
== NULL
) {
42 reqid_ctx
->idr
= idr_init(reqid_ctx
);
43 if (reqid_ctx
->idr
== NULL
) {
44 talloc_free(reqid_ctx
);
51 reqid_ctx
->lastid
= start_id
;
57 uint32_t reqid_new(struct reqid_context
*reqid_ctx
, void *private_data
)
61 id
= idr_get_new_above(reqid_ctx
->idr
, private_data
,
62 reqid_ctx
->lastid
+1, INT_MAX
);
65 id
= idr_get_new(reqid_ctx
->idr
, private_data
, INT_MAX
);
71 reqid_ctx
->lastid
= id
;
75 void *_reqid_find(struct reqid_context
*reqid_ctx
, uint32_t reqid
)
77 return idr_find(reqid_ctx
->idr
, reqid
);
80 int reqid_remove(struct reqid_context
*reqid_ctx
, uint32_t reqid
)
84 ret
= idr_remove(reqid_ctx
->idr
, reqid
);