summaryrefslogtreecommitdiffstats
path: root/posix_api/psx_barrier_report/barrier_attr_report.c
diff options
context:
space:
mode:
Diffstat (limited to 'posix_api/psx_barrier_report/barrier_attr_report.c')
-rw-r--r--posix_api/psx_barrier_report/barrier_attr_report.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/posix_api/psx_barrier_report/barrier_attr_report.c b/posix_api/psx_barrier_report/barrier_attr_report.c
new file mode 100644
index 0000000..c1f0485
--- /dev/null
+++ b/posix_api/psx_barrier_report/barrier_attr_report.c
@@ -0,0 +1,58 @@
+/*
+ * Program to print default POSIX barrier 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>
+
+#ifndef OS_DOES_NOT_SUPPORT_BARRIERS
+
+static void print_shared(pthread_barrierattr_t *attr)
+{
+ int rc;
+ int shared;
+ char *s;
+
+ rc = pthread_barrierattr_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 );
+}
+#endif
+
+int main()
+{
+#ifndef OS_DOES_NOT_SUPPORT_BARRIERS
+ pthread_barrierattr_t attr;
+#endif
+ int rc;
+
+ puts( "*** POSIX Barrier Default Attributes Report ***" );
+
+#ifndef OS_DOES_NOT_SUPPORT_BARRIERS
+ rc = pthread_barrierattr_init( &attr );
+ assert( rc == 0 );
+
+ print_shared( &attr );
+#else
+ printf( "Barriers are not supported\n" );
+#endif
+
+ puts( "*** END OF POSIX Barrier Default Attributes Report ***" );
+ exit( 0 );
+}