Skip to content

Commit 84b6aa0

Browse files
committed
任务1 函数注释补充.修改1
1 parent 6e2071f commit 84b6aa0

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

components/libc/posix/pthreads/pthread.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -142,25 +142,22 @@ pthread_t _pthread_data_create(void)
142142
}
143143

144144
/**
145-
* @brief Create and initialize a new thread data structure with index allocation
145+
* @brief Destroy thread local storage item at specified index
146146
*
147-
* This function allocates memory for a new thread data structure, initializes its default state,
148-
* and registers it in the global thread table. Uses spinlock synchronization to ensure safe
149-
* access to the global thread table in multi-threaded environments.
147+
* This function cleans up thread-local storage data by:
148+
* 1. Checking if the key at given index is active
149+
* 2. If TLS data exists and a destructor is registered, invoking the destructor
150+
* 3. Properly releasing resources associated with the TLS slot
150151
*
151-
* @return Allocated index value of type pthread_t
152-
* - Returns valid index (0~PTHREAD_NUM_MAX-1) on successful allocation
153-
* - Returns PTHREAD_NUM_MAX when memory allocation fails or no space available in thread table
152+
* @param index Index into the thread keys array (0 to PTHREAD_KEY_MAX-1)
153+
* @param ptd Pointer to thread data structure containing TLS information
154154
*
155155
* @note
156-
* - Protects global thread table access with spinlock to prevent data races
157-
* - Uses sequential search to find first available slot in thread table
158-
* - Frees allocated memory and returns error when no available slots
159-
* - Initializes thread data with default states:
160-
* - Cancellation disabled (PTHREAD_CANCEL_DISABLE)
161-
* - Deferred cancellation type (PTHREAD_CANCEL_DEFERRED)
162-
* - Magic number validation (PTHREAD_MAGIC) for structure integrity
163-
* - Explicitly clears magic number before freeing memory to prevent reuse
156+
* - Relies on external spinlock protection when accessing shared data
157+
* - Only processes valid keys that have been initialized
158+
* - Safely handles NULL pointers and missing destructors
159+
* - Designed to be called during thread cleanup or explicit TLS destruction
160+
* - Matches POSIX thread standard requirements for TLS destructor invocation
164161
*/
165162
static inline void _destroy_item(int index, _pthread_data_t *ptd)
166163
{

0 commit comments

Comments
 (0)