1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** POSIX wrapper for THREADX */ 17 /** */ 18 /** */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 /* Include necessary system files. */ 24 25 #include "tx_api.h" /* Threadx API */ 26 #include "pthread.h" /* Posix API */ 27 #include "px_int.h" /* Posix helper functions */ 28 29 30 /**************************************************************************/ 31 /* */ 32 /* FUNCTION RELEASE */ 33 /* */ 34 /* posix_priority_search PORTABLE C */ 35 /* 6.2.0 */ 36 /* AUTHOR */ 37 /* */ 38 /* William E. Lamie, Microsoft Corporation */ 39 /* */ 40 /* DESCRIPTION */ 41 /* */ 42 /* This routine returns the no. of messages of the same priority */ 43 /* in the message queue. */ 44 /* */ 45 /* INPUT */ 46 /* */ 47 /* msgQId message queue ID */ 48 /* priority priority of the message */ 49 /* */ 50 /* OUTPUT */ 51 /* */ 52 /* order Returns the number of same priority messages.*/ 53 /* */ 54 /* CALLS */ 55 /* */ 56 /* None */ 57 /* */ 58 /* CALLED BY */ 59 /* */ 60 /* POSIX internal Code */ 61 /* */ 62 /* RELEASE HISTORY */ 63 /* */ 64 /* DATE NAME DESCRIPTION */ 65 /* */ 66 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ 67 /* 10-31-2022 Scott Larson Add 64-bit support, */ 68 /* resulting in version 6.2.0 */ 69 /* */ 70 /**************************************************************************/ posix_priority_search(mqd_t msgQId,ULONG priority)71ULONG posix_priority_search(mqd_t msgQId, ULONG priority) 72 { 73 74 TX_QUEUE *queue; 75 POSIX_MSG_QUEUE *q_ptr; 76 ULONG order = 1; 77 ULONG numMsgs; 78 UINT index; 79 ULONG *source; 80 ULONG msgp; 81 82 queue = &(msgQId->f_data->queue); 83 q_ptr = (POSIX_MSG_QUEUE * )queue; 84 85 /* No. of messages in the queue. */ 86 numMsgs = q_ptr -> queue.tx_queue_enqueued; 87 88 /* retrieving the message pointer. */ 89 source = q_ptr->queue.tx_queue_read; 90 91 /* check for same priority. */ 92 for(index = 0; index < numMsgs; index++) 93 { 94 source += TX_POSIX_QUEUE_PRIORITY_OFFSET; 95 msgp = *source; 96 source += (TX_POSIX_MESSAGE_SIZE - TX_POSIX_QUEUE_PRIORITY_OFFSET); 97 98 /* If we're at end of queue, go to start. */ 99 if(source == q_ptr->queue.tx_queue_end) 100 source = q_ptr->queue.tx_queue_start; 101 102 /* Increment priority count. */ 103 if(priority == msgp) 104 order += 1; 105 } 106 107 /* Return the number of same priority messages. */ 108 return(order); 109 } 110