diff options
author | Mattias Andrée <maandree@kth.se> | 2020-04-24 19:47:41 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2020-04-24 19:47:41 +0200 |
commit | 90cd52ece1623f9b872837a88504faeb9fd593f6 (patch) | |
tree | 2c910614d39b0b8dde5eccda25de99a6f360e161 /libaxl_generate_id.c | |
parent | First commit (diff) | |
download | libaxl-90cd52ece1623f9b872837a88504faeb9fd593f6.tar.gz libaxl-90cd52ece1623f9b872837a88504faeb9fd593f6.tar.bz2 libaxl-90cd52ece1623f9b872837a88504faeb9fd593f6.tar.xz |
Second commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'libaxl_generate_id.c')
-rw-r--r-- | libaxl_generate_id.c | 20 |
1 files changed, 20 insertions, 0 deletions
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; +} |