source: rtems/cpukit/posix/src/semgetvalue.c @ 2dd5e6fb

5
Last change on this file since 2dd5e6fb was 2dd5e6fb, checked in by Sebastian Huber <sebastian.huber@…>, on 04/20/16 at 04:43:11

posix: Use _Objects_Get_local() for semaphores

This simplifies the code since the object location is no longer used.
Remove superfluous header includes.

  • Property mode set to 100644
File size: 1011 bytes
Line 
1/**
2 * @file
3 *
4 * @brief Get the Value of a Semaphore
5 * @ingroup POSIX_SEMAPHORE
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
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.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <semaphore.h>
22
23#include <rtems/posix/semaphoreimpl.h>
24
25int sem_getvalue(
26  sem_t  *__restrict sem,
27  int    *__restrict sval
28)
29{
30  POSIX_Semaphore_Control *the_semaphore;
31  ISR_lock_Context         lock_context;
32
33  the_semaphore = _POSIX_Semaphore_Get( sem, &lock_context );
34
35  if ( the_semaphore == NULL ) {
36    rtems_set_errno_and_return_minus_one( EINVAL );
37  }
38
39  /*
40   * Assume a relaxed atomic load of the value on SMP configurations.
41   * Thus, there is no need to acquire a lock.
42   */
43  *sval = _CORE_semaphore_Get_count( &the_semaphore->Semaphore );
44
45  _ISR_lock_ISR_enable( &lock_context );
46  return 0;
47}
Note: See TracBrowser for help on using the repository browser.