Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/librumpuser librumpuser: add some #ifdef __APPLE__ and m...



details:   https://anonhg.NetBSD.org/src/rev/0f59a7465431
branches:  trunk
changeset: 790947:0f59a7465431
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sun Oct 27 16:39:46 2013 +0000

description:
librumpuser: add some #ifdef __APPLE__ and missing bits to build it on OS X.
OK pooka@

diffstat:

 lib/librumpuser/rumpuser.c      |  15 ++++++++++-----
 lib/librumpuser/rumpuser_dl.c   |   6 +++---
 lib/librumpuser/rumpuser_port.h |  32 ++++++++++++++++++++++++++++++--
 lib/librumpuser/rumpuser_pth.c  |  14 ++++++++++----
 lib/librumpuser/rumpuser_sp.c   |   6 +++---
 5 files changed, 56 insertions(+), 17 deletions(-)

diffs (232 lines):

diff -r c802ed3c07a1 -r 0f59a7465431 lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c        Sun Oct 27 16:25:01 2013 +0000
+++ b/lib/librumpuser/rumpuser.c        Sun Oct 27 16:39:46 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser.c,v 1.54 2013/08/14 08:29:25 pooka Exp $      */
+/*     $NetBSD: rumpuser.c,v 1.55 2013/10/27 16:39:46 rmind Exp $      */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.54 2013/08/14 08:29:25 pooka Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.55 2013/10/27 16:39:46 rmind Exp $");
 #endif /* !lint */
 
 #include <sys/ioctl.h>
@@ -43,7 +43,12 @@
 #include <sys/dkio.h>
 #endif
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || \
+    defined(__DragonFly__) || defined(__APPLE__)
+#define        __BSD__
+#endif
+
+#if defined(__BSD__)
 #include <sys/sysctl.h>
 #endif
 
@@ -533,7 +538,7 @@
 {
        int ncpu = 1;
 
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__BSD__)
        size_t sz = sizeof(ncpu);
 
        sysctlbyname("hw.ncpu", &ncpu, &sz, NULL, 0);
@@ -607,7 +612,7 @@
        putchar(c);
 }
 
-void
+__dead void
 rumpuser_exit(int rv)
 {
 
diff -r c802ed3c07a1 -r 0f59a7465431 lib/librumpuser/rumpuser_dl.c
--- a/lib/librumpuser/rumpuser_dl.c     Sun Oct 27 16:25:01 2013 +0000
+++ b/lib/librumpuser/rumpuser_dl.c     Sun Oct 27 16:39:46 2013 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rumpuser_dl.c,v 1.21 2013/07/30 18:56:03 pooka Exp $  */
+/*      $NetBSD: rumpuser_dl.c,v 1.22 2013/10/27 16:39:46 rmind Exp $  */
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -40,7 +40,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser_dl.c,v 1.21 2013/07/30 18:56:03 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_dl.c,v 1.22 2013/10/27 16:39:46 rmind Exp $");
 #endif /* !lint */
 
 #include <sys/types.h>
@@ -48,7 +48,6 @@
 #include <assert.h>
 
 #include <dlfcn.h>
-#include <elf.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -61,6 +60,7 @@
 #if defined(__ELF__) && (defined(__NetBSD__) || defined(__FreeBSD__)   \
     || (defined(__sun__) && defined(__svr4__))) || defined(__linux__)  \
     || defined(__DragonFly__)
+#include <elf.h>
 #include <link.h>
 
 static size_t symtabsize = 0, strtabsize = 0;
diff -r c802ed3c07a1 -r 0f59a7465431 lib/librumpuser/rumpuser_port.h
--- a/lib/librumpuser/rumpuser_port.h   Sun Oct 27 16:25:01 2013 +0000
+++ b/lib/librumpuser/rumpuser_port.h   Sun Oct 27 16:39:46 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser_port.h,v 1.21 2013/09/10 17:58:39 pooka Exp $ */
+/*     $NetBSD: rumpuser_port.h,v 1.22 2013/10/27 16:39:46 rmind Exp $ */
 
 /*
  * Portability header for non-NetBSD platforms.
@@ -68,15 +68,43 @@
 #  endif
 #endif
 
+#if defined(__APPLE__)
+#define        __dead          __attribute__((noreturn))
+#include <sys/cdefs.h>
+
+#include <libkern/OSAtomic.h>
+#define        atomic_inc_uint(x)      OSAtomicIncrement32((volatile int32_t *)(x))
+#define        atomic_dec_uint(x)      OSAtomicDecrement32((volatile int32_t *)(x))
+
+#include <sys/time.h>
+
+#define        CLOCK_REALTIME  0
+typedef int clockid_t;
+
+static inline int
+clock_gettime(clockid_t clk, struct timespec *ts)
+{
+       struct timeval tv;
+
+       if (gettimeofday(&tv, 0) == 0) {
+               ts->tv_sec = tv.tv_sec;
+               ts->tv_nsec = tv.tv_usec * 1000;
+       }
+       return -1;
+}
+
+#endif
+
 #include <sys/types.h>
 #include <sys/param.h>
 
 /* maybe this should be !__NetBSD__ ? */
 #if defined(__linux__) || defined(__sun__) || defined(__FreeBSD__)     \
-    || defined(__DragonFly__) || defined(__CYGWIN__)
+    || defined(__DragonFly__) || defined(__APPLE__) || defined(__CYGWIN__)
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
+#include <inttypes.h>
 
 /* this is inline simply to make this header self-contained */
 static inline int 
diff -r c802ed3c07a1 -r 0f59a7465431 lib/librumpuser/rumpuser_pth.c
--- a/lib/librumpuser/rumpuser_pth.c    Sun Oct 27 16:25:01 2013 +0000
+++ b/lib/librumpuser/rumpuser_pth.c    Sun Oct 27 16:39:46 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rumpuser_pth.c,v 1.33 2013/09/26 00:41:51 rmind Exp $  */
+/*     $NetBSD: rumpuser_pth.c,v 1.34 2013/10/27 16:39:46 rmind Exp $  */
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser_pth.c,v 1.33 2013/09/26 00:41:51 rmind Exp $");
+__RCSID("$NetBSD: rumpuser_pth.c,v 1.34 2013/10/27 16:39:46 rmind Exp $");
 #endif /* !lint */
 
 #include <sys/queue.h>
@@ -258,8 +258,10 @@
 
 struct rumpuser_rw {
        pthread_rwlock_t pthrw;
+#if !defined(__APPLE__)
        char pad[64 - sizeof(pthread_rwlock_t)];
        pthread_spinlock_t spin;
+#endif
        unsigned int readers;
        struct lwp *writer;
        int downgrade; /* someone is downgrading (hopefully lock holder ;) */
@@ -319,7 +321,7 @@
 rw_readup(struct rumpuser_rw *rw)
 {
 
-#if defined(__NetBSD__)
+#if defined(__NetBSD__) || defined(__APPLE__)
        atomic_inc_uint(&rw->readers);
 #else
        pthread_spin_lock(&rw->spin);
@@ -332,7 +334,7 @@
 rw_readdown(struct rumpuser_rw *rw)
 {
 
-#if defined(__NetBSD__)
+#if defined(__NetBSD__) || defined(__APPLE__)
        atomic_dec_uint(&rw->readers);
 #else
        pthread_spin_lock(&rw->spin);
@@ -348,7 +350,9 @@
 
        NOFAIL(*rw = aligned_alloc(sizeof(struct rumpuser_rw)));
        NOFAIL_ERRNO(pthread_rwlock_init(&((*rw)->pthrw), NULL));
+#if !defined(__APPLE__)
        NOFAIL_ERRNO(pthread_spin_init(&((*rw)->spin),PTHREAD_PROCESS_PRIVATE));
+#endif
        (*rw)->readers = 0;
        (*rw)->writer = NULL;
        (*rw)->downgrade = 0;
@@ -452,7 +456,9 @@
 {
 
        NOFAIL_ERRNO(pthread_rwlock_destroy(&rw->pthrw));
+#if !defined(__APPLE__)
        NOFAIL_ERRNO(pthread_spin_destroy(&rw->spin));
+#endif
        free(rw);
 }
 
diff -r c802ed3c07a1 -r 0f59a7465431 lib/librumpuser/rumpuser_sp.c
--- a/lib/librumpuser/rumpuser_sp.c     Sun Oct 27 16:25:01 2013 +0000
+++ b/lib/librumpuser/rumpuser_sp.c     Sun Oct 27 16:39:46 2013 +0000
@@ -1,4 +1,4 @@
-/*      $NetBSD: rumpuser_sp.c,v 1.59 2013/07/18 12:28:26 pooka Exp $  */
+/*      $NetBSD: rumpuser_sp.c,v 1.60 2013/10/27 16:39:46 rmind Exp $  */
 
 /*
  * Copyright (c) 2010, 2011 Antti Kantee.  All Rights Reserved.
@@ -37,7 +37,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser_sp.c,v 1.59 2013/07/18 12:28:26 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_sp.c,v 1.60 2013/10/27 16:39:46 rmind Exp $");
 #endif /* !lint */
 
 #include <sys/types.h>
@@ -90,7 +90,7 @@
 
 
 /* how to use atomic ops on Linux? */
-#if defined(__linux__) || defined(__CYGWIN__)
+#if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__)
 static pthread_mutex_t discomtx = PTHREAD_MUTEX_INITIALIZER;
 
 static void



Home | Main Index | Thread Index | Old Index