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 /** ThreadX Component */ 16 /** */ 17 /** Timer */ 18 /** */ 19 /**************************************************************************/ 20 /**************************************************************************/ 21 22 #define TX_SOURCE_CODE 23 24 25 /* Include necessary system files. */ 26 27 #include "tx_api.h" 28 #include "tx_timer.h" 29 30 31 /**************************************************************************/ 32 /* */ 33 /* FUNCTION RELEASE */ 34 /* */ 35 /* _tx_timer_system_deactivate PORTABLE C */ 36 /* 6.1 */ 37 /* AUTHOR */ 38 /* */ 39 /* William E. Lamie, Microsoft Corporation */ 40 /* */ 41 /* DESCRIPTION */ 42 /* */ 43 /* This function deactivates, or removes the timer from the active */ 44 /* timer expiration list. If the timer is already deactivated, this */ 45 /* function just returns. */ 46 /* */ 47 /* INPUT */ 48 /* */ 49 /* timer_ptr Pointer to timer control block */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* TX_SUCCESS Always returns success */ 54 /* */ 55 /* CALLS */ 56 /* */ 57 /* None */ 58 /* */ 59 /* CALLED BY */ 60 /* */ 61 /* _tx_thread_system_resume Thread resume function */ 62 /* _tx_timer_thread_entry Timer thread processing */ 63 /* */ 64 /* RELEASE HISTORY */ 65 /* */ 66 /* DATE NAME DESCRIPTION */ 67 /* */ 68 /* 05-19-2020 William E. Lamie Initial Version 6.0 */ 69 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 70 /* resulting in version 6.1 */ 71 /* */ 72 /**************************************************************************/ _tx_timer_system_deactivate(TX_TIMER_INTERNAL * timer_ptr)73VOID _tx_timer_system_deactivate(TX_TIMER_INTERNAL *timer_ptr) 74 { 75 76 TX_TIMER_INTERNAL **list_head; 77 TX_TIMER_INTERNAL *next_timer; 78 TX_TIMER_INTERNAL *previous_timer; 79 80 81 /* Pickup the list head pointer. */ 82 list_head = timer_ptr -> tx_timer_internal_list_head; 83 84 /* Determine if the timer still needs deactivation. */ 85 if (list_head != TX_NULL) 86 { 87 88 /* Deactivate the timer. */ 89 90 /* Pickup the next active timer. */ 91 next_timer = timer_ptr -> tx_timer_internal_active_next; 92 93 /* See if this is the only timer in the list. */ 94 if (timer_ptr == next_timer) 95 { 96 97 /* Yes, the only timer on the list. */ 98 99 /* Determine if the head pointer needs to be updated. */ 100 if (*(list_head) == timer_ptr) 101 { 102 103 /* Update the head pointer. */ 104 *(list_head) = TX_NULL; 105 } 106 } 107 else 108 { 109 110 /* At least one more timer is on the same expiration list. */ 111 112 /* Update the links of the adjacent timers. */ 113 previous_timer = timer_ptr -> tx_timer_internal_active_previous; 114 next_timer -> tx_timer_internal_active_previous = previous_timer; 115 previous_timer -> tx_timer_internal_active_next = next_timer; 116 117 /* Determine if the head pointer needs to be updated. */ 118 if (*(list_head) == timer_ptr) 119 { 120 121 /* Update the next timer in the list with the list head pointer. */ 122 next_timer -> tx_timer_internal_list_head = list_head; 123 124 /* Update the head pointer. */ 125 *(list_head) = next_timer; 126 } 127 } 128 129 /* Clear the timer's list head pointer. */ 130 timer_ptr -> tx_timer_internal_list_head = TX_NULL; 131 } 132 } 133 134