Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 16 Dec 2011 22:49:13 +0100
From:      Ed Schouten <ed@80386.nl>
To:        threads@freebsd.org, arch@freebsd.org
Subject:   [Patch] C1X threading support
Message-ID:  <20111216214913.GA1771@hoeg.nl>

next in thread | raw e-mail | index | archive | help

--MvEh5MSbieV/1Yst
Content-Type: multipart/mixed; boundary="HSVPcR81XVhxeM7P"
Content-Disposition: inline


--HSVPcR81XVhxeM7P
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi folks,

We can expect C11 (or C12) to be released in the nearby future. I
already took the liberty of adding fallbacks for some of the language
keywords to <sys/cdefs.h>, but it seems the standard also includes a new
threading API.

In my opinion the ISO folks suffer a bit from the Not Invented Here
syndrome. In an earlier revision of the C1X specification, they even
described a `struct xtime', which had a purpose identical to `struct
timespec'. The same holds for the threading API. It can be 1:1 mapped to
a subset of pthread -- why not simply standardize that subset then?

Putting my personal objections aside, I do think we should add support
for the API by the time C1X is final. Attached is a patch that adds the
new API to libthr. It simply wraps all the calls around pthread. Even
the objects used by the API are type compatible with the ones used by
pthread.

The questions:

- As this API is just a second-class citizen and will not be used by the
  C library, I suspect there is no need for underscore prefixing and
  weak aliasing. Is this correct?

- When accompanied with man pages, are there any objections if I commit
  this to SVN when C1X is official?

Thanks,
--=20
 Ed Schouten <ed@80386.nl>
 WWW: http://80386.nl/

--HSVPcR81XVhxeM7P
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="c1x-threads.diff"
Content-Transfer-Encoding: quoted-printable

Index: include/threads.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- include/threads.h	(revision 0)
+++ include/threads.h	(working copy)
@@ -0,0 +1,106 @@
+/*-
+ * Copyright (c) 2012 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT=
IAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR=
ICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W=
AY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _THREADS_H_
+#define	_THREADS_H_
+
+#include <time.h>
+
+/*
+ * The C1X threads interface.
+ *
+ * This interface is implemented as a light-weight wrapper around
+ * <pthread.h>.  To prevent namespace pollution, the once_flag object,
+ * its corresponding ONCE_FLAG_INIT and TSS_DTOR_ITERATIONS have been
+ * copied from this header file.  They must be kept in sync.
+ */
+
+typedef struct pthread_cond	*cnd_t;
+typedef struct pthread_mutex	*mtx_t;
+typedef struct pthread		*thrd_t;
+typedef int			 tss_t;
+
+typedef struct {
+	int	__state;
+	mtx_t	__mutex;
+} once_flag;
+
+typedef void (*tss_dtor_t)(void *);
+typedef int (*thrd_start_t)(void *);
+
+enum {
+	mtx_plain =3D 0x1,
+	mtx_recursive =3D 0x2,
+	mtx_timed =3D 0x4
+};
+
+enum {
+	thrd_busy =3D 1,
+	thrd_error =3D 2,
+	thrd_nomem =3D 3,
+	thrd_success =3D 4,
+	thrd_timedout =3D 5
+};
+
+#if !defined(__cplusplus) || __cplusplus < 201103L
+#define	thread_local		_Thread_local
+#endif
+#define	ONCE_FLAG_INIT		{ 0, NULL }
+#define	TSS_DTOR_ITEARTIONS	4
+
+__BEGIN_DECLS
+void	call_once(once_flag *, void (*)(void));
+int	cnd_broadcast(cnd_t *);
+void	cnd_destroy(cnd_t *);
+int	cnd_init(cnd_t *);
+int	cnd_signal(cnd_t *);
+int	cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict,
+    const struct timespec *__restrict);
+int	cnd_wait(cnd_t *, mtx_t *);
+void	mtx_destroy(mtx_t *);
+int	mtx_init(mtx_t *, int);
+int	mtx_lock(mtx_t *);
+int	mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict);
+int	mtx_trylock(mtx_t *);
+int	mtx_unlock(mtx_t *);
+int	thrd_create(thrd_t *, thrd_start_t, void *);
+thrd_t	thrd_current(void);
+int	thrd_detach(thrd_t);
+int	thrd_equal(thrd_t, thrd_t);
+_Noreturn void
+	thrd_exit(int);
+int	thrd_join(thrd_t, int *);
+int	thrd_sleep(const struct timespec *, struct timespec *);
+void	thrd_yield(void);
+int	tss_create(tss_t *, tss_dtor_t);
+void	tss_delete(tss_t);
+void *	tss_get(tss_t);
+int	tss_set(tss_t, void *);
+__END_DECLS
+
+#endif /* !_THREADS_H_ */
Index: lib/libthr/c1x/c1x_cnd.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/libthr/c1x/c1x_cnd.c	(revision 0)
+++ lib/libthr/c1x/c1x_cnd.c	(working copy)
@@ -0,0 +1,89 @@
+/*-
+ * Copyright (c) 2012 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT=
IAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR=
ICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W=
AY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <errno.h>
+#include <pthread.h>
+#include <threads.h>
+#include "un-namespace.h"
+
+int
+cnd_broadcast(cnd_t *cond)
+{
+
+	if (_pthread_cond_broadcast(cond) !=3D 0)
+		return (thrd_error);
+	return (thrd_success);
+}
+
+void
+cnd_destroy(cnd_t *cond)
+{
+
+	(void)_pthread_cond_destroy(cond);
+}
+
+int
+cnd_init(cnd_t *cond)
+{
+
+	if (_pthread_cond_init(cond, NULL) !=3D 0)
+		return (errno =3D=3D ENOMEM ? thrd_nomem : thrd_error);
+	return (thrd_success);
+}
+
+int
+cnd_signal(cnd_t *cond)
+{
+
+	if (_pthread_cond_signal(cond) !=3D 0)
+		return (thrd_error);
+	return (thrd_success);
+}
+
+int
+cnd_timedwait(cnd_t *restrict cond, mtx_t *restrict mtx,
+    const struct timespec *restrict ts)
+{
+
+	if (_pthread_cond_timedwait(cond, mtx, ts) !=3D 0)
+		return (errno =3D=3D ETIMEDOUT ? thrd_timedout : thrd_error);
+	return (thrd_success);
+}
+
+int
+cnd_wait(cnd_t *cond, mtx_t *mtx)
+{
+
+	if (_pthread_cond_wait(cond, mtx) !=3D 0)
+		return (thrd_error);
+	return (thrd_success);
+}
Index: lib/libthr/c1x/c1x_mtx.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/libthr/c1x/c1x_mtx.c	(revision 0)
+++ lib/libthr/c1x/c1x_mtx.c	(working copy)
@@ -0,0 +1,108 @@
+/*-
+ * Copyright (c) 2012 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT=
IAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR=
ICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W=
AY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <errno.h>
+#include <pthread.h>
+#include <threads.h>
+#include "un-namespace.h"
+
+void
+mtx_destroy(mtx_t *mtx)
+{
+
+	(void)_pthread_mutex_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 =3D PTHREAD_MUTEX_NORMAL;
+		break;
+	case mtx_plain | mtx_recursive:
+	case mtx_timed | mtx_recursive:
+		mt =3D PTHREAD_MUTEX_RECURSIVE;
+		break;
+	default:
+		errno =3D EINVAL;
+		return (thrd_error);
+	}
+
+	if (_pthread_mutexattr_init(&attr) !=3D 0)
+		return (thrd_error);
+	if (_pthread_mutexattr_settype(&attr, mt) !=3D 0)
+		return (thrd_error);
+	if (_pthread_mutex_init(mtx, &attr) !=3D 0)
+		return (thrd_error);
+	return (thrd_success);
+}
+
+int
+mtx_lock(mtx_t *mtx)
+{
+
+	if (_pthread_mutex_lock(mtx) !=3D 0)
+		return (thrd_error);
+	return (thrd_success);
+}
+
+int
+mtx_timedlock(mtx_t *restrict mtx, const struct timespec *restrict ts)
+{
+
+	if (_pthread_mutex_timedlock(mtx, ts) !=3D 0)
+		return (errno =3D=3D ETIMEDOUT ? thrd_timedout : thrd_error);
+	return (thrd_success);
+}
+
+int
+mtx_trylock(mtx_t *mtx)
+{
+
+	if (_pthread_mutex_lock(mtx) !=3D 0)
+		return (errno =3D=3D EBUSY ? thrd_busy : thrd_error);
+	return (thrd_success);
+}
+
+int
+mtx_unlock(mtx_t *mtx)
+{
+
+	if (_pthread_mutex_unlock(mtx) !=3D 0)
+		return (thrd_error);
+	return (thrd_success);
+}
Index: lib/libthr/c1x/c1x_tss.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/libthr/c1x/c1x_tss.c	(revision 0)
+++ lib/libthr/c1x/c1x_tss.c	(working copy)
@@ -0,0 +1,67 @@
+/*-
+ * Copyright (c) 2012 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT=
IAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR=
ICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W=
AY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <pthread.h>
+#include <threads.h>
+#include "un-namespace.h"
+
+int
+tss_create(tss_t *key, tss_dtor_t dtor)
+{
+
+	if (_pthread_key_create(key, dtor) !=3D 0)
+		return (thrd_error);
+	return (thrd_success);
+}
+
+void
+tss_delete(tss_t key)
+{
+
+	(void)_pthread_key_delete(key);
+}
+
+void *
+tss_get(tss_t key)
+{
+
+	return (_pthread_getspecific(key));
+}
+
+int
+tss_set(tss_t key, void *val)
+{
+
+	if (_pthread_setspecific(key, val) !=3D 0)
+		return (thrd_error);
+	return (thrd_success);
+}
Index: lib/libthr/c1x/Makefile.inc
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/libthr/c1x/Makefile.inc	(revision 0)
+++ lib/libthr/c1x/Makefile.inc	(working copy)
@@ -0,0 +1,11 @@
+# $FreeBSD: head/lib/libthr/thread/Makefile.inc 218414 2011-02-07 21:26:46=
Z jkim $
+
+# thr sources
+.PATH: ${.CURDIR}/c1x
+
+SRCS+=3D \
+	c1x_call_once.c \
+	c1x_cnd.c \
+	c1x_mtx.c \
+	c1x_thrd.c \
+	c1x_tss.c
Index: lib/libthr/c1x/c1x_call_once.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/libthr/c1x/c1x_call_once.c	(revision 0)
+++ lib/libthr/c1x/c1x_call_once.c	(working copy)
@@ -0,0 +1,42 @@
+/*-
+ * Copyright (c) 2012 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT=
IAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR=
ICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W=
AY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <pthread.h>
+#include <threads.h>
+#include "un-namespace.h"
+
+void
+call_once(once_flag *flag, void (*func)(void))
+{
+
+	(void)_pthread_once((pthread_once_t *)flag, func);
+}
Index: lib/libthr/c1x/c1x_thrd.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/libthr/c1x/c1x_thrd.c	(revision 0)
+++ lib/libthr/c1x/c1x_thrd.c	(working copy)
@@ -0,0 +1,128 @@
+/*-
+ * Copyright (c) 2012 Ed Schouten <ed@FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURP=
OSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENT=
IAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STR=
ICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY W=
AY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "namespace.h"
+#include <pthread.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <threads.h>
+#include "un-namespace.h"
+
+struct thrd_param {
+	thrd_start_t	 func;
+	void		*arg;
+};
+
+static void *
+thrd_entry(void *arg)
+{
+	struct thrd_param tp;
+
+	tp =3D *(struct thrd_param *)arg;
+	free(arg);
+	return ((void *)(intptr_t)tp.func(tp.arg));
+}
+
+int
+thrd_create(thrd_t *thr, thrd_start_t func, void *arg)
+{
+	struct thrd_param *tp;
+
+	/*
+	 * Work around return type inconsistency.  Wrap execution using
+	 * a function conforming to pthread_create()'s start_routine.
+	 */
+	tp =3D malloc(sizeof(*tp));
+	if (tp =3D=3D NULL)
+		return (thrd_nomem);
+	tp->func =3D func;
+	tp->arg =3D arg;
+	if (_pthread_create(thr, NULL, thrd_entry, tp) !=3D 0) {
+		free(tp);
+		return (thrd_error);
+	}
+	return (thrd_success);
+}
+
+thrd_t
+thrd_current(void)
+{
+
+	return (_pthread_self());
+}
+
+int
+thrd_detach(thrd_t thr)
+{
+
+	if (_pthread_detach(thr) !=3D 0)
+		return (thrd_error);
+	return (thrd_success);
+}
+
+int
+thrd_equal(thrd_t thr0, thrd_t thr1)
+{
+
+	return (_pthread_equal(thr0, thr1));
+}
+
+_Noreturn void
+thrd_exit(int res)
+{
+
+	_pthread_exit((void *)(intptr_t)res);
+}
+
+int
+thrd_join(thrd_t thr, int *res)
+{
+	void *value_ptr;
+
+	if (_pthread_join(thr, &value_ptr) !=3D 0)
+		return (thrd_error);
+	*res =3D (intptr_t)value_ptr;
+	return (thrd_success);
+}
+
+int
+thrd_sleep(const struct timespec *duration, struct timespec *remaining)
+{
+
+	return (_nanosleep(duration, remaining));
+}
+
+void
+thrd_yield(void)
+{
+
+	_pthread_yield();
+}
Index: lib/libthr/pthread.map
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/libthr/pthread.map	(revision 228590)
+++ lib/libthr/pthread.map	(working copy)
@@ -408,3 +408,31 @@
 	setcontext;
 	swapcontext;
 };
+
+FBSD_1.3 {
+	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;
+};
Index: lib/libthr/Makefile
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- lib/libthr/Makefile	(revision 228590)
+++ lib/libthr/Makefile	(working copy)
@@ -47,6 +47,7 @@
 .PATH: ${.CURDIR}/arch/${MACHINE_CPUARCH}/${MACHINE_CPUARCH}
=20
 .include "${.CURDIR}/arch/${MACHINE_CPUARCH}/Makefile.inc"
+.include "${.CURDIR}/c1x/Makefile.inc"
 .include "${.CURDIR}/sys/Makefile.inc"
 .include "${.CURDIR}/thread/Makefile.inc"
=20

--HSVPcR81XVhxeM7P--

--MvEh5MSbieV/1Yst
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (FreeBSD)

iQIbBAEBAgAGBQJO67zZAAoJEG5e2P40kaK7n7sP+KGuwANm6TUNjPHOMFfMewI6
4BBQjsJTzTzdFbqEEqQa5dNwd6fQOparlJ8A9jVHvIS/MD+IHGtbV8R9znb9a2um
Fpsy0VCqt7jEcqOXARMYaupO0w8oVbwwSiuWEiIahYRkgxq76z7jEL80sM7n5HbN
X7ftkjEQ5pcjEPqTHlSKQdD6HVP7M8qUqoanZ+r+HMHNgqwMKJuOXBHxKIpyMolC
xZbGyH4etKGmLIiRVGqCOPrkzHDck/wMRb6OahZa0wuNNM7tRY//xOmw3OPw7P+0
+Br8jm9CAaDYWq4ajvPqLWOELlMY3Mm8rOaN5lrtFN8qk5Z5GE6LJG1QZIHqgmNR
SGLvdaDskqi6QVGq4hTOaKbANTl+MJ0O+XWEBVq2yasQSYQt1b1jlBPIw3KIpAXh
PsIolPEycGhwpvmhmOvfBGnVddh1HpFYIcMeq/N33R3CIDhtQtrypbK2H/t3qpN2
5AV1WyTqeLelfBeb6SNF4TM5BSewA1Bo2okx8ZGynzw5AjN8EXNnSgC6JCqMLxla
u+Whj0bPNU+QT8BZfNO8Ci+wrvEcz1Vx15vfT5MJo/wRRW/STXhRuo4qzlwwMrK3
VxlLtCXUguFEvWxey/InuecVykZF4Fy9HIiF7MOxxpJhSYXHOtBODFg7p8qMHuAE
UIX5gmzMOAXdCUnLUH0=
=g8V1
-----END PGP SIGNATURE-----

--MvEh5MSbieV/1Yst--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111216214913.GA1771>