Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/zephyr/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3913,11 +3913,13 @@
/* Static work queue flags */
K_WORK_QUEUE_NO_YIELD_BIT = 8,
K_WORK_QUEUE_NO_YIELD = BIT(K_WORK_QUEUE_NO_YIELD_BIT),
K_WORK_QUEUE_NO_BLOCK_BIT = 9,
K_WORK_QUEUE_NO_BLOCK = BIT(K_WORK_QUEUE_NO_BLOCK_BIT),

/**
* INTERNAL_HIDDEN @endcond
*/
/* Transient work flags */

Check notice on line 3922 in include/zephyr/kernel.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

include/zephyr/kernel.h:3922 -/** - * INTERNAL_HIDDEN @endcond - */ + /** + * INTERNAL_HIDDEN @endcond + */

/** @brief Flag indicating a work item that is running under a work
* queue thread.
Expand Down Expand Up @@ -4103,6 +4105,9 @@
* essential thread.
*/
bool essential;

/** No Block by handler */
bool no_block;
};

/** @brief A structure used to hold work until it can be processed. */
Expand Down
7 changes: 7 additions & 0 deletions include/zephyr/kernel/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ struct z_poller {
uint8_t mode;
};

enum {
Z_THREAD_NO_BLOCK = 0,
};

/**
* @ingroup thread_apis
* Thread Structure
Expand All @@ -269,6 +273,9 @@ struct k_thread {
/** threads waiting in k_thread_join() */
_wait_q_t join_queue;

/** flags */
atomic_t flags;

#if defined(CONFIG_POLL)
struct z_poller poller;
#endif /* CONFIG_POLL */
Expand Down
4 changes: 4 additions & 0 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@ int z_pend_curr(struct k_spinlock *lock, k_spinlock_key_t key,
#endif /* CONFIG_TIMESLICING && CONFIG_SWAP_NONATOMIC */
__ASSERT_NO_MSG(sizeof(_sched_spinlock) == 0 || lock != &_sched_spinlock);

if (atomic_test_bit(&(_current->flags), Z_THREAD_NO_BLOCK)) {
return -ECANCELED;
}

/* We do a "lock swap" prior to calling z_swap(), such that
* the caller's lock gets released as desired. But we ensure
* that we hold the scheduler lock and leave local interrupts
Expand Down
17 changes: 16 additions & 1 deletion kernel/work.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@
struct k_work *work = NULL;
k_work_handler_t handler = NULL;
k_spinlock_key_t key = k_spin_lock(&lock);
bool yield;
bool yield, block;

/* Check for and prepare any new work. */
node = sys_slist_get(&queue->pending);
Expand Down Expand Up @@ -684,9 +684,20 @@

k_spin_unlock(&lock, key);

block = !flag_test(&queue->flags, K_WORK_QUEUE_NO_BLOCK_BIT);
if (!block) {
atomic_set_bit(&(k_work_queue_thread_get(queue)->flags),
Z_THREAD_NO_BLOCK);
}

Check notice on line 691 in kernel/work.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

kernel/work.c:691 - atomic_set_bit(&(k_work_queue_thread_get(queue)->flags), - Z_THREAD_NO_BLOCK); + atomic_set_bit(&(k_work_queue_thread_get(queue)->flags), Z_THREAD_NO_BLOCK);

__ASSERT_NO_MSG(handler != NULL);
handler(work);

if (!block) {
atomic_clear_bit(&(k_work_queue_thread_get(queue)->flags),
Z_THREAD_NO_BLOCK);
}

/* Mark the work item as no longer running and deal
* with any cancellation and flushing issued while it
* was running. Clear the BUSY flag and optionally
Expand Down Expand Up @@ -747,6 +758,10 @@
flags |= K_WORK_QUEUE_NO_YIELD;
}

if ((cfg != NULL) && cfg->no_block) {
flags |= K_WORK_QUEUE_NO_BLOCK;
}

/* It hasn't actually been started yet, but all the state is in place
* so we can submit things and once the thread gets control it's ready
* to roll.
Expand Down
9 changes: 7 additions & 2 deletions subsys/bluetooth/host/hci_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -4393,12 +4393,17 @@
k_fifo_init(&bt_dev.cmd_tx_queue);

#if defined(CONFIG_BT_RECV_WORKQ_BT)
struct k_work_queue_config bt_workq_cfg = {
.name = "BT RX WQ",
.no_block = true,
};

/* RX thread */
k_work_queue_init(&bt_workq);

k_work_queue_start(&bt_workq, rx_thread_stack,
CONFIG_BT_RX_STACK_SIZE,
K_PRIO_COOP(CONFIG_BT_RX_PRIO), NULL);
k_thread_name_set(&bt_workq.thread, "BT RX WQ");
K_PRIO_COOP(CONFIG_BT_RX_PRIO), &bt_workq_cfg);

Check notice on line 4406 in subsys/bluetooth/host/hci_core.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

subsys/bluetooth/host/hci_core.c:4406 - k_work_queue_start(&bt_workq, rx_thread_stack, - CONFIG_BT_RX_STACK_SIZE, + k_work_queue_start(&bt_workq, rx_thread_stack, CONFIG_BT_RX_STACK_SIZE,
#endif

#if DT_HAS_CHOSEN(zephyr_bt_hci)
Expand Down
Loading