source: rtems/cpukit/posix/src/semaphorewaitsupp.c @ be1b8a7

4.115
Last change on this file since be1b8a7 was e36f2b8, checked in by Sebastian Huber <sebastian.huber@…>, on 07/18/13 at 12:27:30

score: Avoid direct usage of _Thread_Executing

Pass the executing thread as a function parameter. Obtain the executing
thread inside a thread dispatch critical section to avoid problems on
SMP.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief POSIX Semaphore Wait Support
5 * @ingroup POSIXSemaphorePrivate
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2012.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <stdarg.h>
22
23#include <errno.h>
24#include <fcntl.h>
25#include <pthread.h>
26#include <semaphore.h>
27#include <limits.h>
28
29#include <rtems/system.h>
30#include <rtems/score/object.h>
31#include <rtems/posix/semaphoreimpl.h>
32#include <rtems/posix/time.h>
33#include <rtems/seterr.h>
34
35int _POSIX_Semaphore_Wait_support(
36  sem_t             *sem,
37  bool               blocking,
38  Watchdog_Interval  timeout
39)
40{
41  POSIX_Semaphore_Control *the_semaphore;
42  Objects_Locations        location;
43  Thread_Control          *executing;
44
45  the_semaphore = _POSIX_Semaphore_Get( sem, &location );
46  switch ( location ) {
47
48    case OBJECTS_LOCAL:
49      executing = _Thread_Executing;
50      _CORE_semaphore_Seize(
51        &the_semaphore->Semaphore,
52        executing,
53        the_semaphore->Object.id,
54        blocking,
55        timeout
56      );
57      _Objects_Put( &the_semaphore->Object );
58
59      if ( !executing->Wait.return_code )
60        return 0;
61
62      rtems_set_errno_and_return_minus_one(
63        _POSIX_Semaphore_Translate_core_semaphore_return_code(
64          executing->Wait.return_code
65        )
66      );
67
68#if defined(RTEMS_MULTIPROCESSING)
69    case OBJECTS_REMOTE:
70#endif
71    case OBJECTS_ERROR:
72      break;
73  }
74
75  rtems_set_errno_and_return_minus_one( EINVAL );
76}
Note: See TracBrowser for help on using the repository browser.