summaryrefslogtreecommitdiffstats
path: root/testsuites/sptests/spfatal_support/consume_sems.c
blob: adb190104693c475a94d7a134cd8dbef58094cba (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 *  COPYRIGHT (c) 1989-2012.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <rtems.h>

/* forward declarations to avoid warnings */
rtems_device_driver consume_semaphores_initialize(
  rtems_device_major_number major __attribute__((unused)),
  rtems_device_minor_number minor __attribute__((unused)),
  void *pargp __attribute__((unused))
);

#define MAXIMUM 20
rtems_id Semaphores[MAXIMUM];

rtems_device_driver consume_semaphores_initialize(
  rtems_device_major_number major __attribute__((unused)),
  rtems_device_minor_number minor __attribute__((unused)),
  void *pargp __attribute__((unused))
)
{
  int               sems;
  rtems_status_code status;

  for ( sems=0 ; sems<MAXIMUM ; sems++ ) {
    status = rtems_semaphore_create(
      rtems_build_name( 'S', 'M', '1', ' ' ),
      1,
      RTEMS_DEFAULT_MODES,
      RTEMS_NO_PRIORITY,
      &Semaphores[sems]
    );
    if ( status == RTEMS_TOO_MANY )
     break;
  }

  #if 0
    printk( "Consumed %d\n", sems );
    printk( "Freeing %d\n", SEMAPHORES_REMAINING );
  #endif

  #if defined(SEMAPHORES_REMAINING)
  {
    int i;

    for ( i=0 ; i<SEMAPHORES_REMAINING ; i++ ) {
      (void) rtems_semaphore_delete( Semaphores[i] );
    }
  }
  #endif
  return RTEMS_SUCCESSFUL;
}