summaryrefslogtreecommitdiff
path: root/utility/rtos_compatibility_layers/posix/px_system_manager.c
blob: ef24202be1948887d5c121ebe78a0b4ba8158ff5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation 
 * 
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 * 
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */ 
/** POSIX wrapper for THREADX                                             */ 
/**                                                                       */
/**                                                                       */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

/* Include necessary system files.  */

#include "tx_api.h"     /* Threadx API */
#include "pthread.h"    /* Posix API */
#include "px_int.h"     /* Posix helper functions */

/**************************************************************************/ 
/*                                                                        */ 
/*  FUNCTION                                               RELEASE        */ 
/*                                                                        */ 
/*    posix_system_manager_entry                          PORTABLE C      */ 
/*                                                           6.2.0        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    William E. Lamie, Microsoft Corporation                             */
/*                                                                        */
/*  DESCRIPTION                                                           */ 
/*                                                                        */ 
/*    This is the System Manager thread for the POSIX> The system         */
/*    manager thread cleans up terminated threads and releases            */
/*    the stack memory associated with the thread                         */
/*                                                                        */ 
/*  INPUT                                                                 */ 
/*                                                                        */ 
/*    input                                       Not used                */  
/*                                                                        */ 
/*  OUTPUT                                                                */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLS                                                                 */ 
/*                                                                        */
/*    tx_queue_receive                            Receive system request  */ 
/*    posix_do_pthread_delete                     Delete a pthread        */
/*                                                                        */
/*  CALLED BY                                                             */ 
/*                                                                        */ 
/*    Start-up code                                                       */ 
/*                                                                        */ 
/*  RELEASE HISTORY                                                       */ 
/*                                                                        */ 
/*    DATE              NAME                      DESCRIPTION             */
/*                                                                        */
/*  06-02-2021      William E. Lamie        Initial Version 6.1.7         */
/*  10-31-2022      Scott Larson            Add 64-bit support,           */
/*                                            resulting in version 6.2.0  */
/*                                                                        */
/**************************************************************************/
VOID  posix_system_manager_entry(ULONG input)
{

UINT        status;
ULONG       request[WORK_REQ_SIZE];

POSIX_TCB   *pthread_ptr;
VOID        *value_ptr;

    /* Avoid compiler warning.  */
    TX_PARAMETER_NOT_USED(input);

    /* Loop forever, waiting for work requests.  */ 
    while(1)
    {
        /* Wait forever for the next work request.  */
        status = tx_queue_receive(&posix_work_queue, &request, TX_WAIT_FOREVER);
        /* Make sure we didn't encounter any trouble.  */ 
        if (status != TX_SUCCESS)
        {
            /* Get the next message.  */
            continue;
        }
        
        #ifdef TX_64_BIT
        pthread_ptr = (POSIX_TCB *)((((ALIGN_TYPE)request[0]) << 32) | request[1]);
        value_ptr = (VOID *)((((ALIGN_TYPE)request[2]) << 32) | request[3]);
        #else
        pthread_ptr = (POSIX_TCB *)request[0];
        value_ptr = (VOID *)request[1];
        #endif

        /* Delete the pthread  */
        posix_do_pthread_delete(pthread_ptr, value_ptr);
        
    } /* System Manager forever loop  */
}