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 /** NetX Component */ 17 /** */ 18 /** Transmission Control Protocol (TCP) */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 #define NX_SOURCE_CODE 24 25 26 /* Include necessary system files. */ 27 28 #include "nx_api.h" 29 #include "nx_tcp.h" 30 #include "tx_thread.h" 31 32 33 /**************************************************************************/ 34 /* */ 35 /* FUNCTION RELEASE */ 36 /* */ 37 /* _nx_tcp_socket_thread_resume PORTABLE C */ 38 /* 6.1 */ 39 /* AUTHOR */ 40 /* */ 41 /* Yuxin Zhou, Microsoft Corporation */ 42 /* */ 43 /* DESCRIPTION */ 44 /* */ 45 /* This function resumes a thread suspended on a TCP service within */ 46 /* NetX. */ 47 /* */ 48 /* INPUT */ 49 /* */ 50 /* thread_ptr Pointer to thread to resume */ 51 /* status Return status */ 52 /* */ 53 /* OUTPUT */ 54 /* */ 55 /* None */ 56 /* */ 57 /* CALLS */ 58 /* */ 59 /* _tx_thread_system_resume Resume suspended thread */ 60 /* */ 61 /* CALLED BY */ 62 /* */ 63 /* _nx_tcp_client_socket_unbind Client socket unbind */ 64 /* processing */ 65 /* _nx_tcp_socket_connection_reset Received reset processing */ 66 /* _nx_tcp_socket_state_closing Socket state closing */ 67 /* processing */ 68 /* _nx_tcp_socket_state_data_check Socket data check processing */ 69 /* _nx_tcp_socket_state_fin_wait2 Socket FIN wait-2 processing */ 70 /* _nx_tcp_socket_state_fin_wait1 Socket FIN wait-1 processing */ 71 /* _nx_tcp_socket_state_last_ack Socket last ack processing */ 72 /* _nx_tcp_socket_state_syn_received Socket SYN received */ 73 /* processing */ 74 /* _nx_tcp_socket_state_syn_sent Socket SYN sent processing */ 75 /* _nx_tcp_socket_state_transmit_check Socket transmit check */ 76 /* processing */ 77 /* */ 78 /* RELEASE HISTORY */ 79 /* */ 80 /* DATE NAME DESCRIPTION */ 81 /* */ 82 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 83 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 84 /* resulting in version 6.1 */ 85 /* */ 86 /**************************************************************************/ _nx_tcp_socket_thread_resume(TX_THREAD ** suspension_list_head,UINT status)87VOID _nx_tcp_socket_thread_resume(TX_THREAD **suspension_list_head, UINT status) 88 { 89 90 TX_INTERRUPT_SAVE_AREA 91 92 TX_THREAD *thread_ptr; 93 94 95 /* Disable interrupts. */ 96 TX_DISABLE 97 98 /* Pickup the thread pointer. */ 99 thread_ptr = *suspension_list_head; 100 101 /* Determine if there still is a thread suspended. */ 102 if (thread_ptr) 103 { 104 105 /* Determine if there are anymore threads on the suspension list. */ 106 if (thread_ptr == thread_ptr -> tx_thread_suspended_next) 107 { 108 109 /* Only this thread is on the suspension list. Simply set the 110 list head to NULL to reflect an empty suspension list. */ 111 *suspension_list_head = TX_NULL; 112 } 113 else 114 { 115 116 /* More than one thread is on the suspension list, we need to 117 adjust the link pointers and move the next entry to the 118 front of the list. */ 119 *suspension_list_head = thread_ptr -> tx_thread_suspended_next; 120 121 /* Update the links of the adjacent threads. */ 122 (thread_ptr -> tx_thread_suspended_next) -> tx_thread_suspended_previous = 123 thread_ptr -> tx_thread_suspended_previous; 124 (thread_ptr -> tx_thread_suspended_previous) -> tx_thread_suspended_next = 125 thread_ptr -> tx_thread_suspended_next; 126 } 127 128 /* Prepare for resumption of the thread. */ 129 130 /* Clear cleanup routine to avoid timeout. */ 131 thread_ptr -> tx_thread_suspend_cleanup = TX_NULL; 132 133 /* Temporarily disable preemption. */ 134 _tx_thread_preempt_disable++; 135 136 /* Restore interrupts. */ 137 TX_RESTORE 138 139 /* Put return status into the thread control block. */ 140 thread_ptr -> tx_thread_suspend_status = status; 141 142 /* Resume thread. */ 143 _tx_thread_system_resume(thread_ptr); 144 } 145 else 146 { 147 148 /* Nothing was suspended. Simply restore interrupts. */ 149 TX_RESTORE 150 } 151 } 152 153