mirror of
https://github.com/apache/nuttx.git
synced 2026-08-20 21:18:23 +00:00
libc/pthread: return EBUSY when barrier is in use
MIRTOS-114 Add check for semcount==0 before barrier destroy and initialization Change-Id: Ifa0cdb363714ad15eafa5ef49a025520ce836b1f Signed-off-by: Peter Bee <bijunda1@xiaomi.com>
This commit is contained in:
parent
ac9251049b
commit
d4080a4058
2 changed files with 22 additions and 4 deletions
|
|
@ -77,6 +77,7 @@
|
|||
int pthread_barrier_destroy(FAR pthread_barrier_t *barrier)
|
||||
{
|
||||
int ret = OK;
|
||||
int semcount;
|
||||
|
||||
if (!barrier)
|
||||
{
|
||||
|
|
@ -84,8 +85,16 @@ int pthread_barrier_destroy(FAR pthread_barrier_t *barrier)
|
|||
}
|
||||
else
|
||||
{
|
||||
sem_destroy(&barrier->sem);
|
||||
barrier->count = 0;
|
||||
nxsem_get_value(&barrier->sem, &semcount);
|
||||
if (semcount == 0)
|
||||
{
|
||||
sem_destroy(&barrier->sem);
|
||||
barrier->count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = EBUSY;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ int pthread_barrier_init(FAR pthread_barrier_t *barrier,
|
|||
FAR const pthread_barrierattr_t *attr, unsigned int count)
|
||||
{
|
||||
int ret = OK;
|
||||
int semcount;
|
||||
|
||||
if (!barrier || count == 0)
|
||||
{
|
||||
|
|
@ -95,8 +96,16 @@ int pthread_barrier_init(FAR pthread_barrier_t *barrier,
|
|||
}
|
||||
else
|
||||
{
|
||||
sem_init(&barrier->sem, 0, 0);
|
||||
barrier->count = count;
|
||||
nxsem_get_value(&barrier->sem, &semcount);
|
||||
if (semcount == 0)
|
||||
{
|
||||
sem_init(&barrier->sem, 0, 0);
|
||||
barrier->count = count;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = EBUSY;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue