Skip to content

Commit

Permalink
net: openthread: radio: switch to new API for k_work_pending
Browse files Browse the repository at this point in the history
Uses of k_work_pending are to be replaced by k_work_is_pending which
conforms to current proposed naming guidelines.

Switch to the new function.

Also initialize the private work structure at build time, rather than
on each iteration (it is not permitted to invoke work API on an
uninitialized work item).

The implementation here is racy: that a work item is pending does not
mean changes since it was first submitted are guaranteed to be seen
when the work item begins (began) executing.

A better solution would be to have transmit_message be able to
determine whether there is unprocessed work.  Then the work item can
be submitted unconditionally.

Signed-off-by: Peter Bigot <[email protected]>
  • Loading branch information
pabigot authored and nashif committed Mar 4, 2021
1 parent e373004 commit 7b8bce8
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions subsys/net/lib/openthread/platform/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,13 @@ int notify_new_tx_frame(struct net_pkt *pkt)

static int run_tx_task(otInstance *aInstance)
{
static struct k_work tx_job;
static K_WORK_DEFINE(tx_job, transmit_message);

ARG_UNUSED(aInstance);

if (k_work_pending(&tx_job) == 0) {
if (!k_work_is_pending(&tx_job)) {
sState = OT_RADIO_STATE_TRANSMIT;

k_work_init(&tx_job, transmit_message);
k_work_submit_to_queue(&ot_work_q, &tx_job);
return 0;
} else {
Expand Down

0 comments on commit 7b8bce8

Please sign in to comment.