From ee11ed7f8d16902deb8dce9c351569c082d5cdfe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=A7al=20Comajoan=20Cara?= Date: Sun, 9 Dec 2018 15:16:30 +0100 Subject: Add some Livermore pthread examples (GCI 2013/2018) The initial conversion was done by Christopher Kerl as part of GCI 2013. Finally merged as part of GCI 2018. This is part of the Livermore pthread examples from https://computing.llnl.gov/tutorials/pthreads/ Closes #2087. --- posix_api/Makefile | 1 + posix_api/livermore/Makefile | 8 ++++ posix_api/livermore/pthread/Makefile | 23 +++++++++++ posix_api/livermore/pthread/README | 5 +++ posix_api/livermore/pthread/init.c | 80 ++++++++++++++++++++++++++++++++++++ posix_api/livermore/pthread/wscript | 13 ++++++ posix_api/livermore/wscript | 10 +++++ posix_api/wscript | 1 + 8 files changed, 141 insertions(+) create mode 100644 posix_api/livermore/Makefile create mode 100644 posix_api/livermore/pthread/Makefile create mode 100644 posix_api/livermore/pthread/README create mode 100644 posix_api/livermore/pthread/init.c create mode 100644 posix_api/livermore/pthread/wscript create mode 100644 posix_api/livermore/wscript diff --git a/posix_api/Makefile b/posix_api/Makefile index 8af26dc..601246c 100644 --- a/posix_api/Makefile +++ b/posix_api/Makefile @@ -14,4 +14,5 @@ ifeq ($(RTEMS_HAS_POSIX_API),yes) SUBDIRS += psx_pthread_report SUBDIRS += psx_rwlock_report SUBDIRS += psx_sched_report + SUBDIRS += livermore endif diff --git a/posix_api/livermore/Makefile b/posix_api/livermore/Makefile new file mode 100644 index 0000000..d8695a1 --- /dev/null +++ b/posix_api/livermore/Makefile @@ -0,0 +1,8 @@ +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(RTEMS_SHARE)/make/directory.cfg + +# If the POSIX API isn't enabled, we can't build these +ifeq ($(RTEMS_HAS_POSIX_API),yes) + SUBDIRS = pthread +endif diff --git a/posix_api/livermore/pthread/Makefile b/posix_api/livermore/pthread/Makefile new file mode 100644 index 0000000..fdd13dc --- /dev/null +++ b/posix_api/livermore/pthread/Makefile @@ -0,0 +1,23 @@ +# +# RTEMS_MAKEFILE_PATH is typically set in an environment variable +# + +PGM=${ARCH}/pthread.exe + +# optional managers required +MANAGERS=all + +# C source names +CSRCS = init.c +COBJS = $(CSRCS:%.c=${ARCH}/%.o) + +include $(RTEMS_MAKEFILE_PATH)/Makefile.inc +include $(RTEMS_CUSTOM) +include $(PROJECT_ROOT)/make/leaf.cfg + +OBJS= $(COBJS) $(CXXOBJS) $(ASOBJS) + +all: ${ARCH} $(PGM) + +$(PGM): $(OBJS) + $(make-exe) \ No newline at end of file diff --git a/posix_api/livermore/pthread/README b/posix_api/livermore/pthread/README new file mode 100644 index 0000000..17cefd4 --- /dev/null +++ b/posix_api/livermore/pthread/README @@ -0,0 +1,5 @@ +This is a simple example which illustrates how to use the +pthreads adapted from the Lawrence Livermore POSIX Pthreads +tutorial: ​https://computing.llnl.gov/tutorials/pthreads/. + +Thanks to Christopher Kerl for providing the code. diff --git a/posix_api/livermore/pthread/init.c b/posix_api/livermore/pthread/init.c new file mode 100644 index 0000000..bbc296b --- /dev/null +++ b/posix_api/livermore/pthread/init.c @@ -0,0 +1,80 @@ +/* + * COPYRIGHT (c) 1989-2012. + * On-Line Applications Research Corporation (OAR). + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rtems.com/license/LICENSE. + */ + +//Adapted from Lawrence Livermore Pthread Tutorial #1 +//https://computing.llnl.gov/tutorials/pthreads + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include /* for device driver prototypes */ +#include +#include +#include + +#define NUM_THREADS 5 + +/* forward declarations to avoid warnings */ +void *POSIX_Init(void *argument); +void *Print_Hello(void *threadid); + +void *Print_Hello(void *threadid) +{ + long tid; + tid = (long)threadid; + printf("Hello World! It's me, thread #%ld!\n", tid); + + //You must include the return 'NULL;' in your threads to make the compiler happy + pthread_exit(NULL); + return NULL; +} + + +void *POSIX_Init(void *argument) +{ + pthread_t threads[NUM_THREADS]; + int rc; + long t; + + //Creates threads + for(t=0; t diff --git a/posix_api/livermore/pthread/wscript b/posix_api/livermore/pthread/wscript new file mode 100644 index 0000000..6011a02 --- /dev/null +++ b/posix_api/livermore/pthread/wscript @@ -0,0 +1,13 @@ +# Copyright 2018 Marçal Comajoan Cara +# +# This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. +# + +import rtems_waf.rtems as rtems + +def build(bld): + rtems.build(bld) + + bld(features = 'c cprogram', + target = 'pthread.exe', + source = ['init.c']) diff --git a/posix_api/livermore/wscript b/posix_api/livermore/wscript new file mode 100644 index 0000000..da99c30 --- /dev/null +++ b/posix_api/livermore/wscript @@ -0,0 +1,10 @@ +# Copyright 2018 Marçal Comajoan Cara +# +# This file's license is 2-clause BSD as in this distribution's LICENSE.2 file. +# + +import rtems_waf.rtems as rtems + +def build(bld): + if rtems.check_posix(bld): + bld.recurse('pthread') diff --git a/posix_api/wscript b/posix_api/wscript index 66a351f..912063b 100644 --- a/posix_api/wscript +++ b/posix_api/wscript @@ -17,3 +17,4 @@ def build(bld): bld.recurse('psx_pthread_report') bld.recurse('psx_rwlock_report') bld.recurse('psx_sched_report') + bld.recurse('livermore') -- cgit v1.2.3