<commit_before>/*
 * Copyright (c) 2022 Intel Corporation.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/rtio/rtio_executor_simple.h>
#include <zephyr/rtio/rtio.h>
#include <zephyr/kernel.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(rtio_executor_simple, CONFIG_RTIO_LOG_LEVEL);


/**
 * @brief Submit submissions to simple executor
 *
 * The simple executor provides no concurrency instead
 * execution each submission chain one after the next.
 *
 * @param r RTIO context
 *
 * @retval 0 Always succeeds
 */
int rtio_simple_submit(struct rtio *r)
{
	/* TODO For each submission queue entry chain,
	 * submit the chain to the first iodev
	 */
	struct rtio_sqe *sqe = rtio_spsc_consume(r->sq);

	if (sqe != NULL) {
		rtio_iodev_submit(sqe, r);
	}

	return 0;
}

/**
 * @brief Callback from an iodev describing success
 */
void rtio_simple_ok(struct rtio *r, const struct rtio_sqe *sqe, int result)
{
	rtio_cqe_submit(r, result, sqe->userdata);
	rtio_spsc_release(r->sq);
	rtio_simple_submit(r);
}

/**
 * @brief Callback from an iodev describing error
 */
void rtio_simple_err(struct rtio *r, const struct rtio_sqe *sqe, int result)
{
	struct rtio_sqe *nsqe;
	bool chained;

	rtio_cqe_submit(r, result, sqe->userdata);
	chained = sqe->flags & RTIO_SQE_CHAINED;
	rtio_spsc_release(r->sq);

	if (chained) {

		nsqe = rtio_spsc_consume(r->sq);
		while (nsqe != NULL && nsqe->flags & RTIO_SQE_CHAINED) {
			rtio_cqe_submit(r, -ECANCELED, nsqe->userdata);
			rtio_spsc_release(r->sq);
			nsqe = rtio_spsc_consume(r->sq);
		}

		if (nsqe != NULL) {
			rtio_iodev_submit(nsqe, r);
		}

	} else {
		/* Now we can submit the next in the queue if we aren't done */
		rtio_simple_submit(r);
	}
}
<commit_msg>rtio: Release sqe before submitting cqe<commit_after>/*
 * Copyright (c) 2022 Intel Corporation.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/rtio/rtio_executor_simple.h>
#include <zephyr/rtio/rtio.h>
#include <zephyr/kernel.h>

#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(rtio_executor_simple, CONFIG_RTIO_LOG_LEVEL);


/**
 * @brief Submit submissions to simple executor
 *
 * The simple executor provides no concurrency instead
 * execution each submission chain one after the next.
 *
 * @param r RTIO context
 *
 * @retval 0 Always succeeds
 */
int rtio_simple_submit(struct rtio *r)
{
	/* TODO For each submission queue entry chain,
	 * submit the chain to the first iodev
	 */
	struct rtio_sqe *sqe = rtio_spsc_consume(r->sq);

	if (sqe != NULL) {
		rtio_iodev_submit(sqe, r);
	}

	return 0;
}

/**
 * @brief Callback from an iodev describing success
 */
void rtio_simple_ok(struct rtio *r, const struct rtio_sqe *sqe, int result)
{
	void *userdata = sqe->userdata;

	rtio_spsc_release(r->sq);
	rtio_cqe_submit(r, result, userdata);
	rtio_simple_submit(r);
}

/**
 * @brief Callback from an iodev describing error
 */
void rtio_simple_err(struct rtio *r, const struct rtio_sqe *sqe, int result)
{
	struct rtio_sqe *nsqe;
	void *userdata = sqe->userdata;
	bool chained = sqe->flags & RTIO_SQE_CHAINED;

	rtio_spsc_release(r->sq);
	rtio_cqe_submit(r, result, sqe->userdata);

	if (chained) {

		nsqe = rtio_spsc_consume(r->sq);
		while (nsqe != NULL && nsqe->flags & RTIO_SQE_CHAINED) {
			userdata = nsqe->userdata;
			rtio_spsc_release(r->sq);
			rtio_cqe_submit(r, -ECANCELED, userdata);
			nsqe = rtio_spsc_consume(r->sq);
		}

		if (nsqe != NULL) {
			rtio_iodev_submit(nsqe, r);
		}

	} else {
		/* Now we can submit the next in the queue if we aren't done */
		rtio_simple_submit(r);
	}
}

{'fraction_non_alphanumeric': 0.12436691052335397, 'fraction_numerical': 0.004501969611705121, 'mean_word_length': 4.182215743440233, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4021994', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1440, 'n_words': 336}