source: rtems/cpukit/posix/src/pbarrierwait.c @ 77fbbd6

5
Last change on this file since 77fbbd6 was c3105894, checked in by Sebastian Huber <sebastian.huber@…>, on 10/19/17 at 11:47:57

score: Move thread queue timeout handling

Update #3117.
Update #3182.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Wait at a Barrier
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  Copyright (c) 2017 embedded brains GmbH
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <rtems/posix/barrierimpl.h>
24#include <rtems/posix/posixapi.h>
25
26int pthread_barrier_wait( pthread_barrier_t *_barrier )
27{
28  POSIX_Barrier_Control *barrier;
29  Thread_queue_Context   queue_context;
30  Thread_Control        *executing;
31  unsigned int           waiting_threads;
32
33  POSIX_BARRIER_VALIDATE_OBJECT( _barrier );
34
35  barrier = _POSIX_Barrier_Get( _barrier );
36
37  executing = _POSIX_Barrier_Queue_acquire( barrier, &queue_context );
38  waiting_threads = barrier->waiting_threads;
39  ++waiting_threads;
40
41  if ( waiting_threads == barrier->count ) {
42    barrier->waiting_threads = 0;
43    _Thread_queue_Flush_critical(
44      &barrier->Queue.Queue,
45      POSIX_BARRIER_TQ_OPERATIONS,
46      _Thread_queue_Flush_default_filter,
47      &queue_context
48    );
49    return PTHREAD_BARRIER_SERIAL_THREAD;
50  } else {
51    barrier->waiting_threads = waiting_threads;
52    _Thread_queue_Context_set_thread_state(
53      &queue_context,
54      STATES_WAITING_FOR_BARRIER
55    );
56    _Thread_queue_Context_set_enqueue_do_nothing_extra( &queue_context );
57    _Thread_queue_Enqueue(
58      &barrier->Queue.Queue,
59      POSIX_BARRIER_TQ_OPERATIONS,
60      executing,
61      &queue_context
62    );
63    return 0;
64  }
65}
Note: See TracBrowser for help on using the repository browser.