Skip to content

Commit 5a2bc1c

Browse files
hujun260xiaoxiang781216
authored andcommitted
system: pthread_barrierwait can not be preemption
Signed-off-by: hujun5 <[email protected]>
1 parent 16f1dcf commit 5a2bc1c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

libs/libc/pthread/pthread_barrierwait.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424

2525
#include <nuttx/config.h>
2626

27+
#include <nuttx/irq.h>
2728
#include <pthread.h>
2829
#include <semaphore.h>
29-
#include <sched.h>
3030
#include <errno.h>
3131
#include <debug.h>
3232

@@ -82,6 +82,7 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier)
8282
{
8383
int semcount;
8484
int ret = OK;
85+
irqstate_t flags;
8586

8687
if (!barrier)
8788
{
@@ -90,14 +91,14 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier)
9091

9192
/* Disable pre-emption throughout the following */
9293

93-
sched_lock();
94+
flags = enter_critical_section();
9495

9596
/* Find out how many threads are already waiting at the barrier */
9697

9798
ret = sem_getvalue(&barrier->sem, &semcount);
9899
if (ret != OK)
99100
{
100-
sched_unlock();
101+
leave_critical_section(flags);
101102
return get_errno();
102103
}
103104

@@ -115,7 +116,7 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier)
115116

116117
/* Then return PTHREAD_BARRIER_SERIAL_THREAD to the final thread */
117118

118-
sched_unlock();
119+
leave_critical_section(flags);
119120
return PTHREAD_BARRIER_SERIAL_THREAD;
120121
}
121122
else
@@ -133,7 +134,7 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier)
133134
* problem
134135
*/
135136

136-
sched_unlock();
137+
leave_critical_section(flags);
137138
return errornumber;
138139
}
139140
}
@@ -143,7 +144,7 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier)
143144
* zero.
144145
*/
145146

146-
sched_unlock();
147+
leave_critical_section(flags);
147148
return 0;
148149
}
149150
}

0 commit comments

Comments
 (0)