From 90cd52ece1623f9b872837a88504faeb9fd593f6 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 24 Apr 2020 19:47:41 +0200 Subject: Second commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libaxl_generate_id.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 libaxl_generate_id.c (limited to 'libaxl_generate_id.c') diff --git a/libaxl_generate_id.c b/libaxl_generate_id.c new file mode 100644 index 0000000..232ef4d --- /dev/null +++ b/libaxl_generate_id.c @@ -0,0 +1,20 @@ +/* See LICENSE file for copyright and license details. */ +#include "common.h" + +libaxl_id_t +libaxl_generate_id(LIBAXL_CONTEXT *ctx) +{ + LIBAXL_CONNECTION *conn = ctx->conn; + uint32_t id; + + id = atomic_fetch_add(&conn->xid_last, 1); + if (id <= conn->xid_max) + return (id << conn->xid_shift) | conn->xid_base; + + atomic_fetch_sub(&conn->xid_last, 1); + + liberror_save_backtrace(NULL); + liberror_set_error("Request has been buffered and is ready to be sent", + "libaxl_generate_id", "libaxl", LIBAXL_ERROR_OUT_OF_RESOURCE_IDS); + return 0; +} -- cgit v1.2.3-70-g09d2