1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #include "spdk/thread.h" 7 8 bool g_scheduler_delay = false; 9 10 struct scheduled_ops { 11 spdk_msg_fn fn; 12 void *ctx; 13 14 TAILQ_ENTRY(scheduled_ops) ops_queue; 15 }; 16 17 static TAILQ_HEAD(, scheduled_ops) g_scheduled_ops = TAILQ_HEAD_INITIALIZER(g_scheduled_ops); 18 19 void _bs_flush_scheduler(uint32_t); 20 21 static void 22 _bs_send_msg(spdk_msg_fn fn, void *ctx, void *thread_ctx) 23 { 24 if (g_scheduler_delay) { 25 struct scheduled_ops *ops = calloc(1, sizeof(*ops)); 26 27 SPDK_CU_ASSERT_FATAL(ops != NULL); 28 ops->fn = fn; 29 ops->ctx = ctx; 30 TAILQ_INSERT_TAIL(&g_scheduled_ops, ops, ops_queue); 31 32 } else { 33 fn(ctx); 34 } 35 } 36 37 static void 38 _bs_flush_scheduler_single(void) 39 { 40 struct scheduled_ops *op; 41 TAILQ_HEAD(, scheduled_ops) ops; 42 TAILQ_INIT(&ops); 43 44 TAILQ_SWAP(&g_scheduled_ops, &ops, scheduled_ops, ops_queue); 45 46 while (!TAILQ_EMPTY(&ops)) { 47 op = TAILQ_FIRST(&ops); 48 TAILQ_REMOVE(&ops, op, ops_queue); 49 50 op->fn(op->ctx); 51 free(op); 52 } 53 } 54 55 void 56 _bs_flush_scheduler(uint32_t n) 57 { 58 while (n--) { 59 _bs_flush_scheduler_single(); 60 } 61 } 62