source: rtems/testsuites/support/src/locked_print.c @ 047e8aa

5
Last change on this file since 047e8aa was 047e8aa, checked in by Sebastian Huber <sebastian.huber@…>, on 01/19/18 at 08:53:18

tests: Remove unused locked_printk()

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#ifdef HAVE_CONFIG_H
11#include "config.h"
12#endif
13
14#include "test_support.h"
15#include "tmacros.h"
16
17#include <unistd.h>
18#include <rtems/bspIo.h>
19#include <rtems/counter.h>
20
21static rtems_id locked_print_semaphore;      /* synchronisation semaphore */
22
23static int locked_printf_plugin(void *context, const char *fmt, va_list ap)
24{
25  (void) context;
26  return locked_vprintf(fmt, ap);
27}
28
29void locked_print_initialize(void)
30{
31  rtems_status_code sc;
32  static            bool initted = false;
33
34  if ( initted )
35    return;
36
37  initted = true;
38
39  /* Create/verify synchronisation semaphore */
40  sc = rtems_semaphore_create(
41    rtems_build_name ('S', 'E', 'M', '1'),
42    1,
43    RTEMS_LOCAL                   |
44    RTEMS_BINARY_SEMAPHORE |
45    RTEMS_PRIORITY_CEILING |
46    RTEMS_PRIORITY,
47    1,
48    &locked_print_semaphore
49  );
50  directive_failed( sc, "rtems_semaphore_create" );
51
52  /*
53   * Set up the printer to use the locked printf printer.
54   */
55  rtems_test_printer.context = NULL;
56  rtems_test_printer.printer = locked_printf_plugin;
57}
58
59int locked_vprintf(const char *fmt, va_list ap)
60{
61  int rv;
62  rtems_status_code sc;
63
64  locked_print_initialize();
65
66  /* Lock semaphore without releasing the cpu */
67  sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
68
69  if ( sc != RTEMS_SUCCESSFUL ) {
70    uint8_t e;
71    rtems_counter_ticks w;
72
73    /* Use exponential backoff to avoid a livelock */
74
75    getentropy( &e, sizeof( e ) );
76    w = e + 1;
77
78    do {
79      rtems_counter_delay_ticks( w );
80      w *= 2;
81      sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
82    } while (sc != RTEMS_SUCCESSFUL );
83  }
84
85  rv = vprintf(fmt, ap);
86
87  /* Release the semaphore  */
88  rtems_semaphore_release( locked_print_semaphore );
89
90  return rv;
91}
92
93int locked_printf(const char *fmt, ...)
94{
95  int               rv;
96  va_list           ap;       /* points to each unnamed argument in turn */
97
98  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
99  rv = locked_vprintf(fmt, ap);
100  va_end(ap);        /* clean up when done */
101
102  return rv;
103}
Note: See TracBrowser for help on using the repository browser.