source: rtems/testsuites/support/src/locked_print.c @ 152a2841

4.11
Last change on this file since 152a2841 was 152a2841, checked in by Joel Sherrill <joel.sherrill@…>, on Jun 28, 2011 at 9:09:13 PM

2011-06-28 Joel Sherrill <joel.sherrill@…>

  • configure.ac, support/include/test_support.h:
  • support/src/locked_print.c: New file.
  • Property mode set to 100644
File size: 2.1 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.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <rtems.h>
17#include <rtems/system.h>
18#include <sys/types.h>
19#include <string.h>
20#include <stdarg.h>
21
22#include "tmacros.h"
23
24static rtems_id locked_print_semaphore;      /* synchronisation semaphore */ 
25
26void locked_print_initialize(void)
27{
28  rtems_status_code sc;
29  static            bool initted = false;
30
31  if ( initted )
32    return;
33
34  initted = true;
35
36  /* Create/verify synchronisation semaphore */
37  sc = rtems_semaphore_create(
38    rtems_build_name ('S', 'E', 'M', '1'),
39    1,                                             
40    RTEMS_LOCAL                   |
41    RTEMS_SIMPLE_BINARY_SEMAPHORE |
42    RTEMS_PRIORITY,
43    1,
44    &locked_print_semaphore
45  );
46  directive_failed( sc, "rtems_semaphore_create" );
47}
48
49void locked_printf(const char *fmt, ...) {
50  va_list           ap;       /* points to each unnamed argument in turn */
51  rtems_status_code sc;
52
53  locked_print_initialize();
54
55  /* Lock semaphore without releasing the cpu */
56  do {
57    sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
58  } while (sc != RTEMS_SUCCESSFUL );
59
60
61  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
62  vprintf(fmt, ap);
63  va_end(ap);        /* clean up when done */
64
65  /* Release the semaphore  */
66  sc = rtems_semaphore_release( locked_print_semaphore );
67} 
68
69void locked_printk(const char *fmt, ...) {
70  va_list           ap;       /* points to each unnamed argument in turn */
71  rtems_status_code sc;
72
73
74  locked_print_initialize();
75
76  /* Lock semaphore without releasing the cpu */
77  do {
78    sc = rtems_semaphore_obtain( locked_print_semaphore, RTEMS_NO_WAIT, 0 );
79  } while (sc != RTEMS_SUCCESSFUL );
80
81  va_start(ap, fmt); /* make ap point to 1st unnamed arg */
82  vprintk(fmt, ap);
83  va_end(ap);        /* clean up when done */
84
85  /* Release the semaphore  */
86  sc = rtems_semaphore_release( locked_print_semaphore );
87} 
Note: See TracBrowser for help on using the repository browser.