mirror of
https://gitlab.rtems.org/rtems/rtos/rtems.git
synced 2026-11-09 08:37:58 +08:00
libstdthreads: Add C11 threads
This commit is contained in:
1 parent
e3330899f3
commit
cff773f580
15 files changed
+554
-75
No files matched your search
@@ -16,6 +16,7 @@ SUBDIRS += libmisc
|
||||
SUBDIRS += libmd
|
||||
SUBDIRS += libgnat
|
||||
SUBDIRS += libdl
|
||||
SUBDIRS += libstdthreads
|
||||
SUBDIRS += wrapup
|
||||
|
||||
SUBDIRS += zlib
|
||||
|
||||
@@ -141,6 +141,9 @@ AS_IF([test -n "$rtems_missing_header"],
|
||||
AC_CHECK_HEADERS([semaphore.h])
|
||||
AM_CONDITIONAL([HAVE_SEMAPHORE_H],[test x"$ac_cv_header_semaphore_h" = x"yes"])
|
||||
|
||||
AC_CHECK_HEADERS([threads.h])
|
||||
AM_CONDITIONAL([HAVE_THREADS_H],[test x"$ac_cv_header_threads_h" = x"yes"])
|
||||
|
||||
## error out if libc doesn't provide stdint.h
|
||||
AS_IF([test x"${ac_cv_header_stdint_h}" != xyes],
|
||||
[AC_MSG_ERROR([Required header stdint.h not found])])
|
||||
@@ -481,6 +484,7 @@ libmisc/Makefile
|
||||
libi2c/Makefile
|
||||
libmd/Makefile
|
||||
libdl/Makefile
|
||||
libstdthreads/Makefile
|
||||
zlib/Makefile
|
||||
ftpd/Makefile
|
||||
telnetd/Makefile
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
include $(top_srcdir)/automake/compile.am
|
||||
|
||||
include_HEADERS =
|
||||
|
||||
noinst_LIBRARIES = libstdthreads.a
|
||||
|
||||
libstdthreads_a_CFLAGS = -std=c11
|
||||
libstdthreads_a_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
|
||||
libstdthreads_a_SOURCES =
|
||||
if HAVE_THREADS_H
|
||||
libstdthreads_a_SOURCES += call_once.c
|
||||
libstdthreads_a_SOURCES += cnd.c
|
||||
libstdthreads_a_SOURCES += mtx.c
|
||||
if HAS_PTHREADS
|
||||
libstdthreads_a_SOURCES += thrd.c
|
||||
endif
|
||||
libstdthreads_a_SOURCES += tss.c
|
||||
endif
|
||||
|
||||
include $(top_srcdir)/automake/local.am
|
||||
@@ -26,13 +26,9 @@
|
||||
* $FreeBSD r228904 2011-12-26T21:51:53Z$
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <threads.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "threads.h"
|
||||
|
||||
void
|
||||
call_once(once_flag *flag, void (*func)(void))
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
/*-
|
||||
* Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
|
||||
* Copyright (c) 2015 embedded brains GmbH <info@embedded-brains.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -26,20 +27,14 @@
|
||||
* $FreeBSD r228904 2011-12-26T21:51:53Z$
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <threads.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "threads.h"
|
||||
|
||||
int
|
||||
cnd_broadcast(cnd_t *cond)
|
||||
{
|
||||
|
||||
if (pthread_cond_broadcast(cond) != 0)
|
||||
return (thrd_error);
|
||||
_Condition_Broadcast(cond);
|
||||
return (thrd_success);
|
||||
}
|
||||
|
||||
@@ -47,29 +42,22 @@ void
|
||||
cnd_destroy(cnd_t *cond)
|
||||
{
|
||||
|
||||
(void)pthread_cond_destroy(cond);
|
||||
_Condition_Destroy(cond);
|
||||
}
|
||||
|
||||
int
|
||||
cnd_init(cnd_t *cond)
|
||||
{
|
||||
|
||||
switch (pthread_cond_init(cond, NULL)) {
|
||||
case 0:
|
||||
return (thrd_success);
|
||||
case ENOMEM:
|
||||
return (thrd_nomem);
|
||||
default:
|
||||
return (thrd_error);
|
||||
}
|
||||
_Condition_Initialize(cond);
|
||||
return (thrd_success);
|
||||
}
|
||||
|
||||
int
|
||||
cnd_signal(cnd_t *cond)
|
||||
{
|
||||
|
||||
if (pthread_cond_signal(cond) != 0)
|
||||
return (thrd_error);
|
||||
_Condition_Signal(cond);
|
||||
return (thrd_success);
|
||||
}
|
||||
|
||||
@@ -78,7 +66,7 @@ cnd_timedwait(cnd_t *restrict cond, mtx_t *restrict mtx,
|
||||
const struct timespec *restrict ts)
|
||||
{
|
||||
|
||||
switch (pthread_cond_timedwait(cond, mtx, ts)) {
|
||||
switch (_Condition_Wait_recursive_timed(cond, mtx, ts)) {
|
||||
case 0:
|
||||
return (thrd_success);
|
||||
case ETIMEDOUT:
|
||||
@@ -92,7 +80,6 @@ int
|
||||
cnd_wait(cnd_t *cond, mtx_t *mtx)
|
||||
{
|
||||
|
||||
if (pthread_cond_wait(cond, mtx) != 0)
|
||||
return (thrd_error);
|
||||
_Condition_Wait_recursive(cond, mtx);
|
||||
return (thrd_success);
|
||||
}
|
||||
+11
-37
@@ -1,5 +1,6 @@
|
||||
/*-
|
||||
* Copyright (c) 2011 Ed Schouten <ed@FreeBSD.org>
|
||||
* Copyright (c) 2015 embedded brains GmbH <info@embedded-brains.de>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -26,46 +27,23 @@
|
||||
* $FreeBSD r279326 2015-02-26T16:39:57Z$
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <threads.h>
|
||||
#include <sys/lock.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "threads.h"
|
||||
|
||||
void
|
||||
mtx_destroy(mtx_t *mtx)
|
||||
{
|
||||
|
||||
(void)pthread_mutex_destroy(mtx);
|
||||
_Mutex_recursive_Destroy(mtx);
|
||||
}
|
||||
|
||||
int
|
||||
mtx_init(mtx_t *mtx, int type)
|
||||
{
|
||||
pthread_mutexattr_t attr;
|
||||
int mt;
|
||||
|
||||
switch (type) {
|
||||
case mtx_plain:
|
||||
case mtx_timed:
|
||||
mt = PTHREAD_MUTEX_NORMAL;
|
||||
break;
|
||||
case mtx_plain | mtx_recursive:
|
||||
case mtx_timed | mtx_recursive:
|
||||
mt = PTHREAD_MUTEX_RECURSIVE;
|
||||
break;
|
||||
default:
|
||||
return (thrd_error);
|
||||
}
|
||||
|
||||
if (pthread_mutexattr_init(&attr) != 0)
|
||||
return (thrd_error);
|
||||
if (pthread_mutexattr_settype(&attr, mt) != 0)
|
||||
return (thrd_error);
|
||||
if (pthread_mutex_init(mtx, &attr) != 0)
|
||||
return (thrd_error);
|
||||
(void)type;
|
||||
_Mutex_recursive_Initialize(mtx);
|
||||
return (thrd_success);
|
||||
}
|
||||
|
||||
@@ -73,8 +51,7 @@ int
|
||||
mtx_lock(mtx_t *mtx)
|
||||
{
|
||||
|
||||
if (pthread_mutex_lock(mtx) != 0)
|
||||
return (thrd_error);
|
||||
_Mutex_recursive_Acquire(mtx);
|
||||
return (thrd_success);
|
||||
}
|
||||
|
||||
@@ -82,7 +59,7 @@ int
|
||||
mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts)
|
||||
{
|
||||
|
||||
switch (pthread_mutex_timedlock(mtx, ts)) {
|
||||
switch (_Mutex_recursive_Acquire_timed(mtx, ts)) {
|
||||
case 0:
|
||||
return (thrd_success);
|
||||
case ETIMEDOUT:
|
||||
@@ -96,13 +73,11 @@ int
|
||||
mtx_trylock(mtx_t *mtx)
|
||||
{
|
||||
|
||||
switch (pthread_mutex_trylock(mtx)) {
|
||||
switch (_Mutex_recursive_Try_acquire(mtx)) {
|
||||
case 0:
|
||||
return (thrd_success);
|
||||
case EBUSY:
|
||||
return (thrd_busy);
|
||||
default:
|
||||
return (thrd_error);
|
||||
return (thrd_busy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,7 +85,6 @@ int
|
||||
mtx_unlock(mtx_t *mtx)
|
||||
{
|
||||
|
||||
if (pthread_mutex_unlock(mtx) != 0)
|
||||
return (thrd_error);
|
||||
_Mutex_recursive_Release(mtx);
|
||||
return (thrd_success);
|
||||
}
|
||||
@@ -26,15 +26,12 @@
|
||||
* $FreeBSD r279318 2015-02-26T09:42:03Z$
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <threads.h>
|
||||
#include <pthread.h>
|
||||
#include <sched.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "threads.h"
|
||||
|
||||
struct thrd_param {
|
||||
thrd_start_t func;
|
||||
void *arg;
|
||||
@@ -124,5 +121,5 @@ void
|
||||
thrd_yield(void)
|
||||
{
|
||||
|
||||
pthread_yield();
|
||||
sched_yield();
|
||||
}
|
||||
@@ -26,13 +26,10 @@
|
||||
* $FreeBSD r228904 2011-12-26T21:51:53Z$
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <threads.h>
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include "threads.h"
|
||||
|
||||
int
|
||||
tss_create(tss_t *key, tss_dtor_t dtor)
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ TMP_LIBS += ../libgnat/libgnat.a
|
||||
endif
|
||||
|
||||
TMP_LIBS += ../libcrypt/libcrypt.a
|
||||
TMP_LIBS += ../libstdthreads/libstdthreads.a
|
||||
TMP_LIBS += ../libcsupport/libcsupport.a
|
||||
TMP_LIBS += ../libcsupport/libcalloc.a
|
||||
TMP_LIBS += ../libblock/libblock.a
|
||||
|
||||
@@ -40,6 +40,9 @@ endif
|
||||
if HAS__THREAD_QUEUE_QUEUE
|
||||
_SUBDIRS += spsyslock01
|
||||
endif
|
||||
if HAS_THREADS_H
|
||||
_SUBDIRS += spstdthreads01
|
||||
endif
|
||||
_SUBDIRS += sptasknopreempt01
|
||||
_SUBDIRS += spintrcritical23
|
||||
_SUBDIRS += sptimecounter01
|
||||
|
||||
@@ -33,6 +33,9 @@ AC_CHECK_SIZEOF([time_t])
|
||||
AC_CHECK_TYPES([struct _Thread_queue_Queue],[],[],[#include <sys/lock.h>])
|
||||
AM_CONDITIONAL(HAS__THREAD_QUEUE_QUEUE,test x"${ac_cv_type_struct__Thread_queue_Queue}" = x"yes")
|
||||
|
||||
AC_CHECK_HEADERS([threads.h])
|
||||
AM_CONDITIONAL([HAS_THREADS_H],[test x"$ac_cv_header_threads_h" = x"yes"])
|
||||
|
||||
# Added to newlib pthreads for RTEMS SMP (np), may not be present
|
||||
AC_CHECK_HEADERS([sys/cpuset.h])
|
||||
AM_CONDITIONAL(HAS_CPUSET,test x"${ac_cv_header_sys_cpuset_h}" = x"yes")
|
||||
@@ -43,6 +46,7 @@ AM_CONDITIONAL(HAS_SMP,test "$rtems_cv_RTEMS_SMP" = "yes")
|
||||
|
||||
# Explicitly list all Makefiles here
|
||||
AC_CONFIG_FILES([Makefile
|
||||
spstdthreads01/Makefile
|
||||
spsyslock01/Makefile
|
||||
sptasknopreempt01/Makefile
|
||||
spintrcritical23/Makefile
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
rtems_tests_PROGRAMS = spstdthreads01
|
||||
spstdthreads01_SOURCES = init.c
|
||||
|
||||
dist_rtems_tests_DATA = spstdthreads01.scn spstdthreads01.doc
|
||||
|
||||
include $(RTEMS_ROOT)/make/custom/@RTEMS_BSP@.cfg
|
||||
include $(top_srcdir)/../automake/compile.am
|
||||
include $(top_srcdir)/../automake/leaf.am
|
||||
|
||||
AM_CPPFLAGS += -I$(top_srcdir)/../support/include
|
||||
|
||||
LINK_OBJS = $(spstdthreads01_OBJECTS)
|
||||
LINK_LIBS = $(spstdthreads01_LDLIBS)
|
||||
|
||||
spstdthreads01$(EXEEXT): $(spstdthreads01_OBJECTS) $(spstdthreads01_DEPENDENCIES)
|
||||
@rm -f spstdthreads01$(EXEEXT)
|
||||
$(make-exe)
|
||||
|
||||
include $(top_srcdir)/../automake/local.am
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,35 @@
|
||||
This file describes the directives and concepts tested by this test set.
|
||||
|
||||
test set name: spstdthreads01
|
||||
|
||||
directives:
|
||||
|
||||
- call_once()
|
||||
- cnd_broadcast()
|
||||
- cnd_destroy()
|
||||
- cnd_init()
|
||||
- cnd_signal()
|
||||
- cnd_timedwait()
|
||||
- cnd_wait()
|
||||
- mtx_destroy()
|
||||
- mtx_init()
|
||||
- mtx_lock()
|
||||
- mtx_timedlock()
|
||||
- mtx_trylock()
|
||||
- mtx_unlock()
|
||||
- thrd_create()
|
||||
- thrd_current()
|
||||
- thrd_detach()
|
||||
- thrd_equal()
|
||||
- thrd_exit()
|
||||
- thrd_join()
|
||||
- thrd_sleep()
|
||||
- thrd_yield()
|
||||
- tss_create()
|
||||
- tss_delete()
|
||||
- tss_get()
|
||||
- tss_set()
|
||||
|
||||
concepts:
|
||||
|
||||
- Ensure that the C11 threads API works.
|
||||
@@ -0,0 +1,2 @@
|
||||
*** BEGIN OF TEST SPSTDTHREADS 1 ***
|
||||
*** END OF TEST SPSTDTHREADS 1 ***
|
||||
Reference in new issue
Block a user