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 /* FUNCTION RELEASE */ 32 /* */ 33 /* posix_system_manager_entry PORTABLE C */ 34 /* 6.2.0 */ 35 /* AUTHOR */ 36 /* */ 37 /* William E. Lamie, Microsoft Corporation */ 38 /* */ 39 /* DESCRIPTION */ 40 /* */ 41 /* This is the System Manager thread for the POSIX> The system */ 42 /* manager thread cleans up terminated threads and releases */ 43 /* the stack memory associated with the thread */ 44 /* */ 45 /* INPUT */ 46 /* */ 47 /* input Not used */ 48 /* */ 49 /* OUTPUT */ 50 /* */ 51 /* None */ 52 /* */ 53 /* CALLS */ 54 /* */ 55 /* tx_queue_receive Receive system request */ 56 /* posix_do_pthread_delete Delete a pthread */ 57 /* */ 58 /* CALLED BY */ 59 /* */ 60 /* Start-up 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_system_manager_entry(ULONG input)71VOID posix_system_manager_entry(ULONG input) 72 { 73 74 UINT status; 75 ULONG request[WORK_REQ_SIZE]; 76 77 POSIX_TCB *pthread_ptr; 78 VOID *value_ptr; 79 80 /* Avoid compiler warning. */ 81 TX_PARAMETER_NOT_USED(input); 82 83 /* Loop forever, waiting for work requests. */ 84 while(1) 85 { 86 /* Wait forever for the next work request. */ 87 status = tx_queue_receive(&posix_work_queue, &request, TX_WAIT_FOREVER); 88 /* Make sure we didn't encounter any trouble. */ 89 if (status != TX_SUCCESS) 90 { 91 /* Get the next message. */ 92 continue; 93 } 94 95 #ifdef TX_64_BIT 96 pthread_ptr = (POSIX_TCB *)((((ALIGN_TYPE)request[0]) << 32) | request[1]); 97 value_ptr = (VOID *)((((ALIGN_TYPE)request[2]) << 32) | request[3]); 98 #else 99 pthread_ptr = (POSIX_TCB *)request[0]; 100 value_ptr = (VOID *)request[1]; 101 #endif 102 103 /* Delete the pthread */ 104 posix_do_pthread_delete(pthread_ptr, value_ptr); 105 106 } /* System Manager forever loop */ 107 } 108 109