source: rtems/testsuites/support/src/locked_print.c @ b97bc8bc

4.11
Last change on this file since b97bc8bc was b97bc8bc, checked in by Sebastian Huber <sebastian.huber@…>, on May 7, 2014 at 4:27:19 PM

tests: Add locked_printf_plugin()

Add locked_vprintf(). Return an int just like printf(), etc.

  • Property mode set to 100644
File size: 2.4 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
17static rtems_id locked_print_semaphore;      /* synchronisation semaphore */ 
18
19void locked_print_initialize(void)
20{
21  rtems_status_code sc;
22  static            bool initted = false;
23
24  if ( initted )
25    return;
26
27  initted = true;
28
29  /* Create/verify synchronisation semaphore */
30  sc = rtems_semaphore_create(
31    rtems_build_name ('S', 'E', 'M', '1'),
32    1,                                             
33    RTEMS_LOCAL                   |
34    RTEMS_BINARY_SEMAPHORE |
35    RTEMS_PRIORITY_CEILING |
36    RTEMS_PRIORITY,
37    1,
38    &locked_print_semaphore
39  );
40  directive_failed( sc, "rtems_semaphore_create" );
41}
42
43int locked_vprintf(const char *fmt, va_list ap)
44{
45  int rv;
46  rtems_status_code sc;
47
48  locked_print_initialize();
49
50  /* Lock semaphore without releasing the cpu */
51  do {
52    sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
53  } while (sc != RTEMS_SUCCESSFUL );
54
55  rv = vprintf(fmt, ap);
56
57  /* Release the semaphore  */
58  rtems_semaphore_release( locked_print_semaphore );
59
60  return rv;
61}
62
63int locked_printf_plugin(void *context, const char *fmt, ...)
64{
65  int rv;
66  va_list ap;
67
68  (void) context;
69
70  va_start(ap, fmt);
71  rv = locked_vprintf(fmt, ap);
72  va_end(ap);
73
74  return rv;
75}
76
77int locked_printf(const char *fmt, ...)
78{
79  int               rv;
80  va_list           ap;       /* points to each unnamed argument in turn */
81
82  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
83  rv = locked_vprintf(fmt, ap);
84  va_end(ap);        /* clean up when done */
85
86  return rv;
87}
88
89void locked_printk(const char *fmt, ...)
90{
91  va_list           ap;       /* points to each unnamed argument in turn */
92  rtems_status_code sc;
93
94
95  locked_print_initialize();
96
97  /* Lock semaphore without releasing the cpu */
98  do {
99    sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
100  } while (sc != RTEMS_SUCCESSFUL );
101
102  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
103  vprintk(fmt, ap);
104  va_end(ap);        /* clean up when done */
105
106  /* Release the semaphore  */
107  rtems_semaphore_release( locked_print_semaphore );
108}
Note: See TracBrowser for help on using the repository browser.