[pthread] Fix pthread_detach issue for a none-joinable thread
This commit is contained in:
parent
55e2fabbc5
commit
84a44e58dd
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* File : pthread.c
|
* File : pthread.c
|
||||||
* This file is part of RT-Thread RTOS
|
* This file is part of RT-Thread RTOS
|
||||||
* COPYRIGHT (C) 2012, RT-Thread Development Team
|
* COPYRIGHT (C) 2012 - 2017, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -19,6 +19,8 @@
|
|||||||
*
|
*
|
||||||
* Change Logs:
|
* Change Logs:
|
||||||
* Date Author Notes
|
* Date Author Notes
|
||||||
|
* 2018-01-26 Bernard Fix pthread_detach issue for a none-joinable
|
||||||
|
* thread.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
@ -94,7 +96,9 @@ int pthread_create(pthread_t *tid,
|
|||||||
ptd->magic = PTHREAD_MAGIC;
|
ptd->magic = PTHREAD_MAGIC;
|
||||||
|
|
||||||
if (attr != RT_NULL)
|
if (attr != RT_NULL)
|
||||||
|
{
|
||||||
ptd->attr = *attr;
|
ptd->attr = *attr;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* use default attribute */
|
/* use default attribute */
|
||||||
@ -107,7 +111,9 @@ int pthread_create(pthread_t *tid,
|
|||||||
stack = (void *)rt_malloc(ptd->attr.stack_size);
|
stack = (void *)rt_malloc(ptd->attr.stack_size);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
stack = (void *)(ptd->attr.stack_base);
|
stack = (void *)(ptd->attr.stack_base);
|
||||||
|
}
|
||||||
|
|
||||||
if (stack == RT_NULL)
|
if (stack == RT_NULL)
|
||||||
{
|
{
|
||||||
@ -140,7 +146,9 @@ int pthread_create(pthread_t *tid,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
ptd->joinable_sem = RT_NULL;
|
ptd->joinable_sem = RT_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* set parameter */
|
/* set parameter */
|
||||||
ptd->thread_entry = start;
|
ptd->thread_entry = start;
|
||||||
@ -191,6 +199,14 @@ int pthread_detach(pthread_t thread)
|
|||||||
|
|
||||||
ptd = _pthread_get_data(thread);
|
ptd = _pthread_get_data(thread);
|
||||||
|
|
||||||
|
if (ptd->attr.detachstate == PTHREAD_CREATE_DETACHED)
|
||||||
|
{
|
||||||
|
/* The implementation has detected that the value specified by thread does not refer
|
||||||
|
* to a joinable thread.
|
||||||
|
*/
|
||||||
|
return EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_CLOSE)
|
if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_CLOSE)
|
||||||
{
|
{
|
||||||
/* delete joinable semaphore */
|
/* delete joinable semaphore */
|
||||||
@ -205,6 +221,11 @@ int pthread_detach(pthread_t thread)
|
|||||||
/* release thread allocated stack */
|
/* release thread allocated stack */
|
||||||
rt_free(ptd->tid->stack_addr);
|
rt_free(ptd->tid->stack_addr);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* clean stack addr pointer */
|
||||||
|
ptd->tid->stack_addr = RT_NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if this thread create the local thread data,
|
* if this thread create the local thread data,
|
||||||
@ -257,7 +278,9 @@ int pthread_join (pthread_t thread, void **value_ptr)
|
|||||||
pthread_detach(thread);
|
pthread_detach(thread);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
return ESRCH;
|
return ESRCH;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -532,4 +555,3 @@ int pthread_cancel(pthread_t thread)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
RTM_EXPORT(pthread_cancel);
|
RTM_EXPORT(pthread_cancel);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user