Path: blob/main/crypto/openssl/ssl/quic/quic_reactor_wait_ctx.c
48261 views
/*1* Copyright 2024-2025 The OpenSSL Project Authors. All Rights Reserved.2*3* Licensed under the Apache License 2.0 (the "License"). You may not use4* this file except in compliance with the License. You can obtain a copy5* in the file LICENSE in the source distribution or at6* https://www.openssl.org/source/license.html7*/8#include "internal/quic_reactor_wait_ctx.h"9#include "internal/common.h"10#include "internal/thread_arch.h"11#include <assert.h>1213struct quic_reactor_wait_slot_st {14OSSL_LIST_MEMBER(quic_reactor_wait_slot, QUIC_REACTOR_WAIT_SLOT);15QUIC_REACTOR *rtor; /* primary key */16size_t blocking_count; /* datum */17};1819DEFINE_LIST_OF_IMPL(quic_reactor_wait_slot, QUIC_REACTOR_WAIT_SLOT);2021void ossl_quic_reactor_wait_ctx_init(QUIC_REACTOR_WAIT_CTX *ctx)22{23ossl_list_quic_reactor_wait_slot_init(&ctx->slots);24}2526static void slot_activate(QUIC_REACTOR_WAIT_SLOT *slot)27{28if (++slot->blocking_count == 1)29ossl_quic_reactor_enter_blocking_section(slot->rtor);30}3132static void slot_deactivate(QUIC_REACTOR_WAIT_SLOT *slot)33{34assert(slot->blocking_count > 0);3536if (--slot->blocking_count > 0)37return;3839ossl_quic_reactor_leave_blocking_section(slot->rtor);40}4142int ossl_quic_reactor_wait_ctx_enter(QUIC_REACTOR_WAIT_CTX *ctx,43QUIC_REACTOR *rtor)44{45QUIC_REACTOR_WAIT_SLOT *slot;4647OSSL_LIST_FOREACH(slot, quic_reactor_wait_slot, &ctx->slots)48if (slot->rtor == rtor)49break;5051if (slot == NULL) {52if ((slot = OPENSSL_zalloc(sizeof(QUIC_REACTOR_WAIT_SLOT))) == NULL)53return 0;5455slot->rtor = rtor;56ossl_list_quic_reactor_wait_slot_insert_tail(&ctx->slots, slot);57}5859slot_activate(slot);60return 1;61}6263void ossl_quic_reactor_wait_ctx_leave(QUIC_REACTOR_WAIT_CTX *ctx,64QUIC_REACTOR *rtor)65{66QUIC_REACTOR_WAIT_SLOT *slot;6768OSSL_LIST_FOREACH(slot, quic_reactor_wait_slot, &ctx->slots)69if (slot->rtor == rtor)70break;7172assert(slot != NULL);73slot_deactivate(slot);74}7576void ossl_quic_reactor_wait_ctx_cleanup(QUIC_REACTOR_WAIT_CTX *ctx)77{78QUIC_REACTOR_WAIT_SLOT *slot, *nslot;7980OSSL_LIST_FOREACH_DELSAFE(slot, nslot, quic_reactor_wait_slot, &ctx->slots) {81assert(slot->blocking_count == 0);82OPENSSL_free(slot);83}84}858687