Skip to content
Open
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
4 changes: 4 additions & 0 deletions common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ target_sources(${PROJECT_NAME}
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_delete.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_flush.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_front_send.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_peek.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_peek_release.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_peek_resume.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_info_get.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_initialize.c
${CMAKE_CURRENT_LIST_DIR}/src/tx_queue_performance_info_get.c
Expand Down Expand Up @@ -164,6 +167,7 @@ target_sources(${PROJECT_NAME}
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_delete.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_flush.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_front_send.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_peek.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_info_get.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_prioritize.c
${CMAKE_CURRENT_LIST_DIR}/src/txe_queue_receive.c
Expand Down
6 changes: 6 additions & 0 deletions common/inc/tx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ UINT _tx_trace_interrupt_control(UINT new_posture);
#define tx_queue_send _tx_queue_send
#define tx_queue_send_notify _tx_queue_send_notify
#define tx_queue_front_send _tx_queue_front_send
#define tx_queue_peek _tx_queue_peek
#define tx_queue_prioritize _tx_queue_prioritize

#define tx_semaphore_ceiling_put _tx_semaphore_ceiling_put
Expand Down Expand Up @@ -1250,6 +1251,7 @@ UINT _tx_trace_interrupt_control(UINT new_posture);
#define tx_queue_send _txr_queue_send
#define tx_queue_send_notify _txr_queue_send_notify
#define tx_queue_front_send _txr_queue_front_send
#define tx_queue_peek _txr_queue_peek
#define tx_queue_prioritize _txr_queue_prioritize

#define tx_semaphore_ceiling_put _txr_semaphore_ceiling_put
Expand Down Expand Up @@ -1361,6 +1363,7 @@ UINT _tx_el_interrupt_control(UINT new_posture);
#define tx_queue_send _txe_queue_send
#define tx_queue_send_notify _txe_queue_send_notify
#define tx_queue_front_send _txe_queue_front_send
#define tx_queue_peek _txe_queue_peek
#define tx_queue_prioritize _txe_queue_prioritize

#define tx_semaphore_ceiling_put _txe_semaphore_ceiling_put
Expand Down Expand Up @@ -1620,6 +1623,7 @@ UINT _tx_queue_receive(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG
UINT _tx_queue_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _tx_queue_send_notify(TX_QUEUE *queue_ptr, VOID (*queue_send_notify)(TX_QUEUE *notify_queue_ptr));
UINT _tx_queue_front_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _tx_queue_peek(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option);


/* Define error checking shells for API services. These are only referenced by the
Expand All @@ -1636,6 +1640,7 @@ UINT _txe_queue_receive(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG
UINT _txe_queue_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _txe_queue_send_notify(TX_QUEUE *queue_ptr, VOID (*queue_send_notify)(TX_QUEUE *notify_queue_ptr));
UINT _txe_queue_front_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _txe_queue_peek(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option);
#ifdef TX_ENABLE_MULTI_ERROR_CHECKING
UINT _txr_queue_create(TX_QUEUE *queue_ptr, TX_NAME_CONST CHAR *name_ptr, UINT message_size,
VOID *queue_start, ULONG queue_size, UINT queue_control_block_size);
Expand All @@ -1648,6 +1653,7 @@ UINT _txr_queue_receive(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG
UINT _txr_queue_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _txr_queue_send_notify(TX_QUEUE *queue_ptr, VOID (*queue_send_notify)(TX_QUEUE *notify_queue_ptr));
UINT _txr_queue_front_send(TX_QUEUE *queue_ptr, VOID *source_ptr, ULONG wait_option);
UINT _txr_queue_peek(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option);
#endif


Expand Down
7 changes: 7 additions & 0 deletions common/inc/tx_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
#define TX_QUEUE_ID ((ULONG) 0x51554555)


/* Value of tx_thread_suspend_option for a thread suspended in tx_queue_peek. */

#define TX_QUEUE_PEEK_SUSPEND ((UINT) 2)


/* Determine if in-line component initialization is supported by the
caller. */
#ifdef TX_INVOKE_INLINE_INITIALIZATION
Expand Down Expand Up @@ -96,6 +101,8 @@ VOID _tx_queue_initialize(VOID);
/* Define internal queue management function prototypes. */

VOID _tx_queue_cleanup(TX_THREAD *thread_ptr, ULONG suspension_sequence);
TX_THREAD *_tx_queue_peek_release(TX_QUEUE *queue_ptr, VOID *source_ptr);
VOID _tx_queue_peek_resume(TX_THREAD *thread_list);


/* Queue management component data declarations follow. */
Expand Down
1 change: 1 addition & 0 deletions common/inc/tx_trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ typedef struct TX_TRACE_OBJECT_ENTRY_STRUCT
#define TX_TRACE_QUEUE_RECEIVE 68 /* I1 = queue ptr, I2 = destination ptr, I3 = wait option, I4 = enqueued */
#define TX_TRACE_QUEUE_SEND 69 /* I1 = queue ptr, I2 = source ptr, I3 = wait option, I4 = enqueued */
#define TX_TRACE_QUEUE_SEND_NOTIFY 70 /* I1 = queue ptr */
#define TX_TRACE_QUEUE_PEEK 71 /* I1 = queue ptr, I2 = destination ptr, I3 = wait option, I4 = enqueued */
#define TX_TRACE_SEMAPHORE_CEILING_PUT 80 /* I1 = semaphore ptr, I2 = current count, I3 = suspended count,I4 =ceiling */
#define TX_TRACE_SEMAPHORE_CREATE 81 /* I1 = semaphore ptr, I2 = initial count, I3 = stack ptr */
#define TX_TRACE_SEMAPHORE_DELETE 82 /* I1 = semaphore ptr, I2 = stack ptr */
Expand Down
22 changes: 22 additions & 0 deletions common/src/tx_queue_front_send.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ UINT suspended_count;
TX_THREAD *next_thread;
TX_THREAD *previous_thread;
UINT status;
TX_THREAD *peek_list;
#ifndef TX_DISABLE_NOTIFY_CALLBACKS
VOID (*queue_send_notify)(struct TX_QUEUE_STRUCT *notify_queue_ptr);
#endif
Expand Down Expand Up @@ -115,6 +116,15 @@ VOID (*queue_send_notify)(struct TX_QUEUE_STRUCT *notify_queue_ptr);
if (queue_ptr -> tx_queue_available_storage != ((UINT) 0))
{

/* Peeking threads get a copy; the message is still delivered below. */
peek_list = TX_NULL;
if (suspended_count != TX_NO_SUSPENSIONS)
{

peek_list = _tx_queue_peek_release(queue_ptr, source_ptr);
suspended_count = queue_ptr -> tx_queue_suspended_count;
}

/* Yes there is room in the queue. Now determine if there is a thread waiting
for a message. */
if (suspended_count == TX_NO_SUSPENSIONS)
Expand Down Expand Up @@ -167,6 +177,12 @@ VOID (*queue_send_notify)(struct TX_QUEUE_STRUCT *notify_queue_ptr);
/* Restore interrupts. */
TX_RESTORE

if (peek_list != TX_NULL)
{

_tx_queue_peek_resume(peek_list);
}

#ifndef TX_DISABLE_NOTIFY_CALLBACKS

/* Determine if a notify callback is required. */
Expand Down Expand Up @@ -259,6 +275,12 @@ VOID (*queue_send_notify)(struct TX_QUEUE_STRUCT *notify_queue_ptr);
_tx_thread_system_resume(thread_ptr);
#endif

if (peek_list != TX_NULL)
{

_tx_queue_peek_resume(peek_list);
}

#ifndef TX_DISABLE_NOTIFY_CALLBACKS

/* Determine if a notify callback is required. */
Expand Down
237 changes: 237 additions & 0 deletions common/src/tx_queue_peek.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
/***************************************************************************
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/


/**************************************************************************/
/**************************************************************************/
/** */
/** ThreadX Component */
/** */
/** Queue */
/** */
/**************************************************************************/
/**************************************************************************/

#define TX_SOURCE_CODE


/* Include necessary system files. */

#include "tx_api.h"
#include "tx_trace.h"
#include "tx_thread.h"
#include "tx_queue.h"


/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _tx_queue_peek PORTABLE C */
/* */
/* DESCRIPTION */
/* */
/* This function copies the message at the front of the specified */
/* queue without removing it. The message is the one the next */
/* tx_queue_receive would return. If the queue is empty, this */
/* function waits according to the option specified; a waiting thread */
/* is handed a copy of the next message sent to the queue, and that */
/* message stays in the queue. */
/* */
/* INPUT */
/* */
/* queue_ptr Pointer to queue control block */
/* destination_ptr Pointer to message destination */
/* **** MUST BE LARGE ENOUGH TO */
/* HOLD MESSAGE **** */
/* wait_option Suspension option */
/* */
/* OUTPUT */
/* */
/* status Completion status */
/* */
/* CALLS */
/* */
/* _tx_thread_system_suspend Suspend thread routine */
/* _tx_thread_system_ni_suspend Non-interruptable suspend thread */
/* */
/* CALLED BY */
/* */
/* Application Code */
/* */
/**************************************************************************/
UINT _tx_queue_peek(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option)
{

TX_INTERRUPT_SAVE_AREA

TX_THREAD *thread_ptr;
ULONG *source;
ULONG *destination;
UINT size;
UINT suspended_count;
TX_THREAD *next_thread;
TX_THREAD *previous_thread;
UINT status;


/* Default the status to TX_SUCCESS. */
status = TX_SUCCESS;

/* Disable interrupts to peek at the queue. */
TX_DISABLE

/* If trace is enabled, insert this event into the trace buffer. */
TX_TRACE_IN_LINE_INSERT(TX_TRACE_QUEUE_PEEK, queue_ptr, TX_POINTER_TO_ULONG_CONVERT(destination_ptr), wait_option, queue_ptr -> tx_queue_enqueued, TX_TRACE_QUEUE_EVENTS)

/* Pickup the thread suspension count. */
suspended_count = queue_ptr -> tx_queue_suspended_count;

/* Determine if there is anything in the queue. */
if (queue_ptr -> tx_queue_enqueued != TX_NO_MESSAGES)
{

/* Default to the message at the read pointer. */
source = queue_ptr -> tx_queue_read;

/* Threads suspended on a non-empty queue are senders waiting on a full queue.
A front send suspension at the head is what tx_queue_receive returns next. */
if (suspended_count != TX_NO_SUSPENSIONS)
{

thread_ptr = queue_ptr -> tx_queue_suspension_list;
if (thread_ptr -> tx_thread_suspend_option == TX_TRUE)
{

source = TX_VOID_TO_ULONG_POINTER_CONVERT(thread_ptr -> tx_thread_additional_suspend_info);
}
}

/* Setup destination pointer and size. */
destination = TX_VOID_TO_ULONG_POINTER_CONVERT(destination_ptr);
size = queue_ptr -> tx_queue_message_size;

/* Copy message. Note that the source and destination pointers are
incremented by the macro. */
TX_QUEUE_MESSAGE_COPY(source, destination, size)

/* Restore interrupts. */
TX_RESTORE
}

/* Determine if the request specifies suspension. */
else if (wait_option != TX_NO_WAIT)
{

/* Determine if the preempt disable flag is non-zero. */
if (_tx_thread_preempt_disable != ((UINT) 0))
{

/* Restore interrupts. */
TX_RESTORE

/* Suspension is not allowed if the preempt disable flag is non-zero at this point - return error completion. */
status = TX_QUEUE_EMPTY;
}
else
{

/* Prepare for suspension of this thread. */

/* Pickup thread pointer. */
TX_THREAD_GET_CURRENT(thread_ptr)

/* Setup cleanup routine pointer. */
thread_ptr -> tx_thread_suspend_cleanup = &(_tx_queue_cleanup);

/* Setup cleanup information, i.e. this queue control
block and the destination pointer. */
thread_ptr -> tx_thread_suspend_control_block = (VOID *) queue_ptr;
thread_ptr -> tx_thread_additional_suspend_info = (VOID *) destination_ptr;
thread_ptr -> tx_thread_suspend_option = TX_QUEUE_PEEK_SUSPEND;

#ifndef TX_NOT_INTERRUPTABLE

/* Increment the suspension sequence number, which is used to identify
this suspension event. */
thread_ptr -> tx_thread_suspension_sequence++;
#endif

/* Setup suspension list. */
if (suspended_count == TX_NO_SUSPENSIONS)
{

/* No other threads are suspended. Setup the head pointer and
just setup this threads pointers to itself. */
queue_ptr -> tx_queue_suspension_list = thread_ptr;
thread_ptr -> tx_thread_suspended_next = thread_ptr;
thread_ptr -> tx_thread_suspended_previous = thread_ptr;
}
else
{

/* This list is not NULL, add current thread to the end. */
next_thread = queue_ptr -> tx_queue_suspension_list;
thread_ptr -> tx_thread_suspended_next = next_thread;
previous_thread = next_thread -> tx_thread_suspended_previous;
thread_ptr -> tx_thread_suspended_previous = previous_thread;
previous_thread -> tx_thread_suspended_next = thread_ptr;
next_thread -> tx_thread_suspended_previous = thread_ptr;
}

/* Increment the suspended thread count. */
queue_ptr -> tx_queue_suspended_count = suspended_count + ((UINT) 1);

/* Set the state to suspended. */
thread_ptr -> tx_thread_state = TX_QUEUE_SUSP;

#ifdef TX_NOT_INTERRUPTABLE

/* Call actual non-interruptable thread suspension routine. */
_tx_thread_system_ni_suspend(thread_ptr, wait_option);

/* Restore interrupts. */
TX_RESTORE
#else

/* Set the suspending flag. */
thread_ptr -> tx_thread_suspending = TX_TRUE;

/* Setup the timeout period. */
thread_ptr -> tx_thread_timer.tx_timer_internal_remaining_ticks = wait_option;

/* Temporarily disable preemption. */
_tx_thread_preempt_disable++;

/* Restore interrupts. */
TX_RESTORE

/* Call actual thread suspension routine. */
_tx_thread_system_suspend(thread_ptr);
#endif

/* Return the completion status. */
status = thread_ptr -> tx_thread_suspend_status;
}
}
else
{

/* Restore interrupts. */
TX_RESTORE

/* Immediate return, return error completion. */
status = TX_QUEUE_EMPTY;
}

/* Return completion status. */
return(status);
}

Loading
Loading