summaryrefslogtreecommitdiffstats
path: root/posix_api/psx_condvar_report/condvar_attr_report.c
blob: 4c460d9d0c8d91974a3521f51c74e1cd77d1bb1d (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
64
65
66
67
68
69
/*
 *  Program to print default POSIX condition variable attributes
 */

/*
 * Copyright 2018 Joel Sherrill (joel@rtems.org)
 *
 * This file's license is 2-clause BSD as in this distribution's LICENSE.2 file.
 */

#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <pthread.h>
#include <assert.h>

static void print_shared(pthread_condattr_t *attr)
{
  int   rc;
  int   shared;
  char *s;

  rc = pthread_condattr_getpshared( attr, &shared );
  assert( rc == 0 );

  switch ( shared ) {
    case PTHREAD_PROCESS_PRIVATE: s = "PTHREAD_PROCESS_PRIVATE"; break;
    case PTHREAD_PROCESS_SHARED:  s = "PTHREAD_PROCESS_SHARED"; break;
    default:                      s = "UNKNOWN"; break;
  }

  printf( "Process shared: %s\n", s );
}

static void print_clock(pthread_condattr_t *attr)
{
  int         rc;
  clockid_t   clock;
  char       *s;

  rc = pthread_condattr_getclock( attr, &clock );
  assert( rc == 0 );
  switch ( clock ) {
    case CLOCK_MONOTONIC:          s = "CLOCK_MONOTONIC"; break;
    case CLOCK_PROCESS_CPUTIME_ID: s = "CLOCK_PROCESS_CPUTIME_ID"; break;
    case CLOCK_REALTIME:           s = "CLOCK_REALTIME"; break;
    case CLOCK_THREAD_CPUTIME_ID:  s = "CLOCK_THREAD_CPUTIME_ID"; break;
    default:                       s = "UNKNOWN"; break;
  }

  printf( "Clock: %s\n", s );
}

int main()
{
  pthread_condattr_t  attr;
  int                  rc;
  
  puts( "*** POSIX Condition Variable Default Attributes Report ***" );

  rc = pthread_condattr_init( &attr );
  assert( rc == 0 );

  print_shared( &attr );
  print_clock( &attr );

  puts( "*** END OF POSIX Condition Variable Default Attributes Report ***" );
  exit( 0 );
}