"Sync" threading libaries.
authorHasso Tepper <hasso@estpak.ee>
Mon, 6 Jul 2009 21:11:04 +0000 (00:11 +0300)
committerHasso Tepper <hasso@estpak.ee>
Mon, 6 Jul 2009 21:13:18 +0000 (00:13 +0300)
* 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 and modify sysconf(3)
  accordingly.

include/pthread.h
lib/libc/gen/_pthread_stubs.c
lib/libc/gen/sysconf.c
lib/libc_r/uthread/Makefile.inc
lib/libc_r/uthread/uthread_stubs.c [new file with mode: 0644]
lib/libthread_xu/thread/Makefile.inc
lib/libthread_xu/thread/thr_pspinlock.c
sys/sys/_pthreadtypes.h
sys/sys/unistd.h

index 9d0f06e..bc393be 100644 (file)
@@ -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 *);
index 6a191a6..b8de93d 100644 (file)
@@ -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);
index e13dedf..244aed9 100644 (file)
@@ -341,13 +341,11 @@ yesno:
 #else
                return (_POSIX_ADVISORY_INFO);
 #endif
-#if 0
        case _SC_BARRIERS:
 #if _POSIX_BARRIERS == 0
 #error "_POSIX_BARRIERS"
 #else
                return (_POSIX_BARRIERS);
-#endif
 #endif
        case _SC_CLOCK_SELECTION:
 #if _POSIX_CLOCK_SELECTION == 0
@@ -395,10 +393,8 @@ yesno:
                return (_POSIX_SHELL);
        case _SC_SPAWN:
                return (_POSIX_SPAWN);
-#if 0
        case _SC_SPIN_LOCKS:
                return (_POSIX_SPIN_LOCKS);
-#endif
        case _SC_SPORADIC_SERVER:
 #if _POSIX_SPORADIC_SERVER == 0
 #error "_POSIX_SPORADIC_SERVER"
index 1c79664..3b1f1d5 100644 (file)
@@ -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 (file)
index 0000000..d1c9edd
--- /dev/null
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2009 The DragonFly Project.  All rights reserved.
+ * 
+ * This code is derived from software contributed to The DragonFly Project
+ * by Hasso Tepper <hasso@estpak.ee>
+ * 
+ * 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.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific, prior written permission.
+ * 
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL 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, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#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);
index 33e7c21..6bb4620 100644 (file)
@@ -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 \
index 1219aaf..35aa3ac 100644 (file)
@@ -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);
 }
index 7c32637..9e8cf38 100644 (file)
@@ -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:
index dfa857d..3619359 100644 (file)
@@ -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