How to find number of thread/task suspended on semaphore

Hello,

Is there a way to find out numbers of threads suspended on counting semaphore ?

In our existing operating system, there is API which returns number of threads currently suspended on the semaphore(counting). I am replacing current OS(threadX) with FreeRTOS and wondering if this information available in FreeRTOS ? If so is it possible to retrieve this information in application ?

Any suggestion is appreciated.

Regards,
Query1920

Not out of the box, but this should do what you want:

void vQueueGetNumberOfWaitingTasks( const QueueHandle_t xQueue, UBaseType_t *puxWaitingToSend, UBaseType_t *puxWaitingToReceive )
{
Queue_t * const pxQueue = xQueue;

	configASSERT( pxQueue );

	if( puxWaitingToSend != NULL )
	{
		taskENTER_CRITICAL();
		{
			*puxWaitingToSend = listCURRENT_LIST_LENGTH( &( pxQueue->xTasksWaitingToSend ) );
		}
		taskEXIT_CRITICAL();
	}

	if( puxWaitingToReceive != NULL )
	{
		taskENTER_CRITICAL();
		{
			*puxWaitingToReceive = listCURRENT_LIST_LENGTH( &( pxQueue->xTasksWaitingToReceive ) );
		}
		taskEXIT_CRITICAL();
	}
}

If it works for you feel free to open a pull requests here: https://github.com/FreeRTOS/FreeRTOS-Kernel :grinning:

Thanks for sharing code.
This seems to be working well for what i need. Will be doing more testing on it.

Thanks again