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