1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** POSIX wrapper for THREADX                                             */
16 /**                                                                       */
17 /**                                                                       */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 /* Include necessary system files.  */
23 
24 #include "tx_api.h"     /* Threadx API */
25 #include "pthread.h"    /* Posix API */
26 #include "px_int.h"     /* Posix helper functions */
27 
28 
29 /**************************************************************************/
30 /*                                                                        */
31 /*  FUNCTION                                               RELEASE        */
32 /*                                                                        */
33 /*    posix_get_queue_desc                                PORTABLE C      */
34 /*                                                           6.1.7        */
35 /*  AUTHOR                                                                */
36 /*                                                                        */
37 /*    William E. Lamie, Microsoft Corporation                             */
38 /*                                                                        */
39 /*  DESCRIPTION                                                           */
40 /*                                                                        */
41 /*    This function returns a message queue descriptor pointer of valid   */
42 /*    message queue                                                       */
43 /*                                                                        */
44 /*  INPUT                                                                 */
45 /*                                                                        */
46 /*    q_ptr                         message queue pointer                 */
47 /*                                                                        */
48 /*  OUTPUT                                                                */
49 /*                                                                        */
50 /*    q_des                         message queue descriptor              */
51 /*                                                                        */
52 /*  CALLS                                                                 */
53 /*                                                                        */
54 /*    posix_internal_error          Returns a Generic error               */
55 /*    tx_byte_allocate              Allocates bytes                       */
56 /*                                                                        */
57 /*  CALLED BY                                                             */
58 /*                                                                        */
59 /*    POSIX internal Code                                                 */
60 /*                                                                        */
61 /*  RELEASE HISTORY                                                       */
62 /*                                                                        */
63 /*    DATE              NAME                      DESCRIPTION             */
64 /*                                                                        */
65 /*  06-02-2021     William E. Lamie         Initial Version 6.1.7         */
66 /*                                                                        */
67 /**************************************************************************/
posix_get_queue_des(POSIX_MSG_QUEUE * q_ptr)68 struct mq_des * posix_get_queue_des(POSIX_MSG_QUEUE * q_ptr)
69 {
70 
71 struct mq_des    *q_des = NULL;
72 VOID             *bp;
73 
74     /* allocate the system resource allocated by open call.  */
75     if( tx_byte_allocate((TX_BYTE_POOL *)&posix_heap_byte_pool, &bp,
76                               sizeof(struct mq_des), TX_NO_WAIT))
77     {
78         /* return generic error.  */
79         posix_internal_error(100);
80         /* Return error.  */
81         return((struct mq_des *)ERROR);
82     }
83     q_des = (struct mq_des *)bp;
84     /* Get message queue data to mq_des structure.  */
85     q_des->f_data = q_ptr;
86     return(q_des);
87 }
88