commit e4ca843f2c249bfa2e1102f6f90a9c0829ca5bab
Author: Hasso Tepper <hasso@estpak.ee>
Date:   Sat Jul 4 17:04:40 2009 +0300

    "Sync" threading libaries.
    
    * Introduce stubs returning error into libc_r for functions which don't
      exist there, but are there in libthread_xu.
    * Compile POSIX spinlocks implementation in libthread_xu.
    * Define _POSIX_BARRIERS and _POSIX_SPIN_LOCKS now.

diff --git a/include/pthread.h b/include/pthread.h
index 9d0f06e..bc393be 100644
--- a/include/pthread.h
+++ b/include/pthread.h
@@ -232,6 +232,12 @@ pthread_t	pthread_self(void);
 int		pthread_setspecific(pthread_key_t, const void *);
 int		pthread_sigmask(int, const sigset_t *, sigset_t *);
 
+int		pthread_spin_destroy(pthread_spinlock_t *);
+int		pthread_spin_init(pthread_spinlock_t *, int);
+int		pthread_spin_lock(pthread_spinlock_t *);
+int		pthread_spin_trylock(pthread_spinlock_t *);
+int		pthread_spin_unlock(pthread_spinlock_t *);
+
 int		pthread_cancel(pthread_t);
 int		pthread_setcancelstate(int, int *);
 int		pthread_setcanceltype(int, int *);
diff --git a/lib/libc/gen/_pthread_stubs.c b/lib/libc/gen/_pthread_stubs.c
index 6a191a6..b8de93d 100644
--- a/lib/libc/gen/_pthread_stubs.c
+++ b/lib/libc/gen/_pthread_stubs.c
@@ -49,6 +49,7 @@ WR(stub_zero, pthread_atfork);
 WR(stub_zero, pthread_attr_destroy);
 WR(stub_zero, pthread_attr_get_np);
 WR(stub_zero, pthread_attr_getdetachstate);
+WR(stub_zero, pthread_attr_getguardsize);
 WR(stub_zero, pthread_attr_getinheritsched);
 WR(stub_zero, pthread_attr_getschedparam);
 WR(stub_zero, pthread_attr_getschedpolicy);
@@ -59,6 +60,7 @@ WR(stub_zero, pthread_attr_getstacksize);
 WR(stub_zero, pthread_attr_init);
 WR(stub_zero, pthread_attr_setcreatesuspend_np);
 WR(stub_zero, pthread_attr_setdetachstate);
+WR(stub_zero, pthread_attr_setguardsize);
 WR(stub_zero, pthread_attr_setinheritsched);
 WR(stub_zero, pthread_attr_setschedparam);
 WR(stub_zero, pthread_attr_setschedpolicy);
@@ -66,6 +68,13 @@ WR(stub_zero, pthread_attr_setscope);
 WR(stub_zero, pthread_attr_setstack);
 WR(stub_zero, pthread_attr_setstackaddr);
 WR(stub_zero, pthread_attr_setstacksize);
+WR(stub_zero, pthread_barrier_destroy);
+WR(stub_zero, pthread_barrier_init);
+WR(stub_zero, pthread_barrier_wait);
+WR(stub_zero, pthread_barrierattr_destroy);
+WR(stub_zero, pthread_barrierattr_getpshared);
+WR(stub_zero, pthread_barrierattr_init);
+WR(stub_zero, pthread_barrierattr_setpshared);
 WR(stub_zero, pthread_cancel);
 WR(stub_zero, pthread_cleanup_pop);
 WR(stub_zero, pthread_cleanup_push);
@@ -76,7 +85,11 @@ WR(stub_zero, pthread_cond_signal);
 WR(stub_zero, pthread_cond_timedwait);
 WR(stub_zero, pthread_cond_wait);
 WR(stub_zero, pthread_condattr_destroy);
+WR(stub_zero, pthread_condattr_getclock);
+WR(stub_zero, pthread_condattr_getpshared);
 WR(stub_zero, pthread_condattr_init);
+WR(stub_zero, pthread_condattr_setclock);
+WR(stub_zero, pthread_condattr_setpshared);
 WR(stub_zero, pthread_detach);
 WR(stub_true, pthread_equal);
 WR(stub_exit, pthread_exit);
@@ -95,6 +108,7 @@ WR(stub_zero, pthread_mutex_getprioceiling);
 WR(stub_zero, pthread_mutex_init);
 WR(stub_zero, pthread_mutex_lock);
 WR(stub_zero, pthread_mutex_setprioceiling);
+WR(stub_zero, pthread_mutex_timedlock);
 WR(stub_zero, pthread_mutex_trylock);
 WR(stub_zero, pthread_mutex_unlock);
 WR(stub_zero, pthread_mutexattr_destroy);
@@ -115,6 +129,8 @@ WR(stub_zero, pthread_resume_np);
 WR(stub_zero, pthread_rwlock_destroy);
 WR(stub_zero, pthread_rwlock_init);
 WR(stub_zero, pthread_rwlock_rdlock);
+WR(stub_zero, pthread_rwlock_timedrdlock);
+WR(stub_zero, pthread_rwlock_timedwrlock);
 WR(stub_zero, pthread_rwlock_tryrdlock);
 WR(stub_zero, pthread_rwlock_trywrlock);
 WR(stub_zero, pthread_rwlock_unlock);
@@ -133,11 +149,17 @@ WR(stub_zero, pthread_setschedparam);
 WR(stub_zero, pthread_setspecific);
 WR(stub_zero, pthread_sigmask);
 WR(stub_zero, pthread_single_np);
+WR(stub_zero, pthread_spin_destroy);
+WR(stub_zero, pthread_spin_init);
+WR(stub_zero, pthread_spin_lock);
+WR(stub_zero, pthread_spin_trylock);
+WR(stub_zero, pthread_spin_unlock);
 WR(stub_zero, pthread_suspend_all_np);
 WR(stub_zero, pthread_suspend_np);
 WR(stub_zero, pthread_switch_add_np);
 WR(stub_zero, pthread_switch_delete_np);
 WR(stub_zero, pthread_testcancel);
+WR(stub_zero, pthread_timedjoin_np);
 WR(stub_zero, pthread_yield);
 WR(stub_zero, sched_yield);
 WR(stub_zero, sem_close);
diff --git a/lib/libc_r/uthread/Makefile.inc b/lib/libc_r/uthread/Makefile.inc
index 1c79664..3b1f1d5 100644
--- a/lib/libc_r/uthread/Makefile.inc
+++ b/lib/libc_r/uthread/Makefile.inc
@@ -121,6 +121,7 @@ SRCS+= \
 	uthread_socketpair.c \
 	uthread_spec.c \
 	uthread_spinlock.c \
+	uthread_stubs.c \
 	uthread_suspend_np.c \
 	uthread_switch_np.c \
 	uthread_system.c \
diff --git a/lib/libc_r/uthread/uthread_stubs.c b/lib/libc_r/uthread/uthread_stubs.c
new file mode 100644
index 0000000..511b171
--- /dev/null
+++ b/lib/libc_r/uthread/uthread_stubs.c
@@ -0,0 +1,36 @@
+#include <sys/cdefs.h>
+
+static int __used
+_stub_return_error(void)
+{
+	return (-1);
+}
+
+__strong_reference(_stub_return_error, pthread_attr_getguardsize);
+__strong_reference(_stub_return_error, pthread_attr_setguardsize);
+
+__strong_reference(_stub_return_error, pthread_barrier_destroy);
+__strong_reference(_stub_return_error, pthread_barrier_init);
+__strong_reference(_stub_return_error, pthread_barrier_wait);
+__strong_reference(_stub_return_error, pthread_barrierattr_destroy);
+__strong_reference(_stub_return_error, pthread_barrierattr_getpshared);
+__strong_reference(_stub_return_error, pthread_barrierattr_init);
+__strong_reference(_stub_return_error, pthread_barrierattr_setpshared);
+
+__strong_reference(_stub_return_error, pthread_condattr_getclock);
+__strong_reference(_stub_return_error, pthread_condattr_getpshared);
+__strong_reference(_stub_return_error, pthread_condattr_setclock);
+__strong_reference(_stub_return_error, pthread_condattr_setpshared);
+
+__strong_reference(_stub_return_error, pthread_mutex_timedlock);
+
+__strong_reference(_stub_return_error, pthread_rwlock_timedrdlock);
+__strong_reference(_stub_return_error, pthread_rwlock_timedwrlock);
+
+__strong_reference(_stub_return_error, pthread_timedjoin_np);
+
+__strong_reference(_stub_return_error, pthread_spin_init);
+__strong_reference(_stub_return_error, pthread_spin_destroy);
+__strong_reference(_stub_return_error, pthread_spin_trylock);
+__strong_reference(_stub_return_error, pthread_spin_lock);
+__strong_reference(_stub_return_error, pthread_spin_unlock);
diff --git a/lib/libthread_xu/thread/Makefile.inc b/lib/libthread_xu/thread/Makefile.inc
index 33e7c21..6bb4620 100644
--- a/lib/libthread_xu/thread/Makefile.inc
+++ b/lib/libthread_xu/thread/Makefile.inc
@@ -34,6 +34,7 @@ SRCS+= \
 	thr_mutex_protocol.c \
 	thr_once.c \
 	thr_printf.c \
+	thr_pspinlock.c \
 	thr_resume_np.c \
 	thr_rwlock.c \
 	thr_rwlockattr.c \
diff --git a/lib/libthread_xu/thread/thr_pspinlock.c b/lib/libthread_xu/thread/thr_pspinlock.c
index 1219aaf..35aa3ac 100644
--- a/lib/libthread_xu/thread/thr_pspinlock.c
+++ b/lib/libthread_xu/thread/thr_pspinlock.c
@@ -127,7 +127,8 @@ _pthread_spin_unlock(pthread_spinlock_t *lock)
 	if (lock == NULL || (lck = *lock) == NULL)
 		ret = EINVAL;
 	else {
-		ret = THR_UMTX_UNLOCK(curthread, &lck->s_lock);
+		THR_UMTX_UNLOCK(curthread, &lck->s_lock);
+		ret = 0;
 	}
 	return (ret);
 }
diff --git a/sys/sys/_pthreadtypes.h b/sys/sys/_pthreadtypes.h
index 7c32637..9e8cf38 100644
--- a/sys/sys/_pthreadtypes.h
+++ b/sys/sys/_pthreadtypes.h
@@ -50,6 +50,7 @@ struct pthread_rwlock;
 struct pthread_rwlockattr;
 struct pthread_barrier;
 struct pthread_barrier_attr;
+struct pthread_spinlock;
 
 /*
  * Primitive system data type definitions required by P1003.1c.
@@ -70,6 +71,7 @@ typedef struct	pthread_rwlock		*pthread_rwlock_t;
 typedef struct	pthread_rwlockattr	*pthread_rwlockattr_t;
 typedef struct	pthread_barrier		*pthread_barrier_t;
 typedef struct	pthread_barrierattr	*pthread_barrierattr_t;
+typedef struct	pthread_spinlock	*pthread_spinlock_t;
 
 /*
  * Additional type definitions:
diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h
index dfa857d..3619359 100644
--- a/sys/sys/unistd.h
+++ b/sys/sys/unistd.h
@@ -53,6 +53,7 @@
  */
 #define	_POSIX_ADVISORY_INFO		-1
 #define	_POSIX_ASYNCHRONOUS_IO		0
+#define	_POSIX_BARRIERS			200112L
 #define	_POSIX_CHOWN_RESTRICTED		1
 #define	_POSIX_CLOCK_SELECTION		-1
 #define	_POSIX_CPUTIME			-1
@@ -72,6 +73,7 @@
 #define	_POSIX_REALTIME_SIGNALS		200112L
 #define	_POSIX_SEMAPHORES		-1
 #define	_POSIX_SHARED_MEMORY_OBJECTS	200112L
+#define	_POSIX_SPIN_LOCKS		200112L
 #define	_POSIX_SPORADIC_SERVER		-1
 #define	_POSIX_SYNCHRONIZED_IO		-1
 #define	_POSIX_TIMEOUTS			200112L
