2024-01-29 13:51:15 +08:00
|
|
|
/***************************************************************************
|
|
|
|
* 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
|
|
|
|
**************************************************************************/
|
2020-09-30 15:42:41 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/**************************************************************************/
|
2021-06-02 06:45:05 +00:00
|
|
|
/** */
|
|
|
|
/** POSIX wrapper for THREADX */
|
2020-09-30 15:42:41 -07:00
|
|
|
/** */
|
|
|
|
/** */
|
|
|
|
/** */
|
|
|
|
/**************************************************************************/
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
/* Include necessary system files. */
|
|
|
|
|
2021-06-02 06:45:05 +00:00
|
|
|
#include "tx_api.h" /* Threadx API */
|
|
|
|
#include "pthread.h" /* Posix API */
|
|
|
|
#include "px_int.h" /* Posix helper functions */
|
2020-09-30 15:42:41 -07:00
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************/
|
|
|
|
/* */
|
|
|
|
/* FUNCTION RELEASE */
|
|
|
|
/* */
|
2021-06-02 06:45:05 +00:00
|
|
|
/* pthread_detach PORTABLE C */
|
2021-07-28 07:24:02 +00:00
|
|
|
/* 6.1.7 */
|
2020-09-30 15:42:41 -07:00
|
|
|
/* AUTHOR */
|
|
|
|
/* */
|
2021-06-02 06:45:05 +00:00
|
|
|
/* William E. Lamie, Microsoft Corporation */
|
2020-09-30 15:42:41 -07:00
|
|
|
/* */
|
|
|
|
/* DESCRIPTION */
|
|
|
|
/* */
|
|
|
|
/* */
|
2021-06-02 06:45:05 +00:00
|
|
|
/* The pthread_detach() function indicates that system resources for */
|
|
|
|
/* the specified thread should be reclaimed when the thread ends. */
|
|
|
|
/* If the thread is already ended, resources are reclaimed immediately.*/
|
|
|
|
/* This routine does not cause the thread to end. */
|
|
|
|
/* After pthread_detach() has been issued, it is not valid to try to */
|
|
|
|
/* pthread_join() with the target thread. */
|
|
|
|
/* Eventually, you should call pthread_join() or pthread_detach() for */
|
|
|
|
/* every thread that is created joinable (with a detachstate of */
|
|
|
|
/* PTHREAD_CREATE_JOINABLE)so that the system can reclaim all resources*/
|
|
|
|
/* associated with the thread. Failure to join to or detach joinable */
|
|
|
|
/* threads will result in memory and other resource leaks until the */
|
|
|
|
/* process ends. If thread doesn't represent a valid undetached thread,*/
|
|
|
|
/* pthread_detach() will return ESRCH. */
|
|
|
|
/* */
|
2020-09-30 15:42:41 -07:00
|
|
|
/* */
|
|
|
|
/* INPUT */
|
|
|
|
/* */
|
2021-06-02 06:45:05 +00:00
|
|
|
/* thread pthread handle to the target thread */
|
|
|
|
/* */
|
2020-09-30 15:42:41 -07:00
|
|
|
/* */
|
|
|
|
/* OUTPUT */
|
|
|
|
/* */
|
2021-06-02 06:45:05 +00:00
|
|
|
/* zero If successful */
|
|
|
|
/* error number If fails */
|
2020-09-30 15:42:41 -07:00
|
|
|
/* */
|
|
|
|
/* CALLS */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* CALLED BY */
|
|
|
|
/* */
|
|
|
|
/* Application Code */
|
|
|
|
/* */
|
|
|
|
/* RELEASE HISTORY */
|
|
|
|
/* */
|
|
|
|
/* DATE NAME DESCRIPTION */
|
|
|
|
/* */
|
2021-07-28 07:24:02 +00:00
|
|
|
/* 06-02-2021 William E. Lamie Initial Version 6.1.7 */
|
2020-09-30 15:42:41 -07:00
|
|
|
/* */
|
|
|
|
/**************************************************************************/
|
2021-06-02 06:45:05 +00:00
|
|
|
INT pthread_detach(pthread_t thread)
|
|
|
|
|
2020-09-30 15:42:41 -07:00
|
|
|
{
|
|
|
|
|
|
|
|
TX_INTERRUPT_SAVE_AREA
|
|
|
|
|
2021-06-02 06:45:05 +00:00
|
|
|
POSIX_TCB *pthread_ptr;
|
2020-09-30 15:42:41 -07:00
|
|
|
|
2021-06-02 06:45:05 +00:00
|
|
|
TX_DISABLE
|
2020-09-30 15:42:41 -07:00
|
|
|
|
2021-06-02 06:45:05 +00:00
|
|
|
pthread_ptr = posix_tid2tcb(thread);
|
|
|
|
if(pthread_ptr==NULL)
|
|
|
|
{
|
|
|
|
TX_RESTORE
|
|
|
|
return(ESRCH);
|
|
|
|
}
|
|
|
|
if(pthread_ptr->is_detached==TX_TRUE)
|
|
|
|
{
|
|
|
|
TX_RESTORE
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
pthread_ptr->is_detached = TX_TRUE;
|
|
|
|
|
2020-09-30 15:42:41 -07:00
|
|
|
TX_RESTORE
|
2021-06-02 06:45:05 +00:00
|
|
|
return(OK);
|
2020-09-30 15:42:41 -07:00
|
|
|
}
|