Source-Changes-HG archive

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

[src/trunk]: src/common/lib/libprop Bit-un-rot the proplib portability layer.



details:   https://anonhg.NetBSD.org/src/rev/d4b15f0997da
branches:  trunk
changeset: 780494:d4b15f0997da
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Jul 27 09:10:59 2012 +0000

description:
Bit-un-rot the proplib portability layer.

diffstat:

 common/lib/libprop/Makefile.inc           |     6 +-
 common/lib/libprop/prop_array.c           |     8 +-
 common/lib/libprop/prop_array_util.c      |     4 +-
 common/lib/libprop/prop_dictionary.c      |    12 +-
 common/lib/libprop/prop_dictionary_util.c |     4 +-
 common/lib/libprop/prop_ingest.c          |     4 +-
 common/lib/libprop/prop_number.c          |     7 +-
 common/lib/libprop/prop_object.c          |    25 +-
 common/lib/libprop/prop_object_impl.h     |    58 +-
 common/lib/libprop/prop_rb.c              |  1130 +++++++++++++++++-----------
 common/lib/libprop/prop_rb_impl.h         |   190 ++-
 11 files changed, 886 insertions(+), 562 deletions(-)

diffs (truncated from 2198 to 300 lines):

diff -r 3dd7168d2ec0 -r d4b15f0997da common/lib/libprop/Makefile.inc
--- a/common/lib/libprop/Makefile.inc   Fri Jul 27 09:09:05 2012 +0000
+++ b/common/lib/libprop/Makefile.inc   Fri Jul 27 09:10:59 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.8 2008/06/30 20:14:09 matt Exp $
+#      $NetBSD: Makefile.inc,v 1.9 2012/07/27 09:10:59 pooka Exp $
 
 .PATH: ${.PARSEDIR}
 
@@ -6,4 +6,6 @@
         prop_dictionary.c prop_dictionary_util.c prop_ingest.c \
         prop_kern.c prop_number.c prop_object.c prop_stack.c prop_string.c
 
-#SRCS+=        prop_rb.c
+.ifdef (PROPLIB_WANT_RB)
+SRCS+= prop_rb.c
+.endif
diff -r 3dd7168d2ec0 -r d4b15f0997da common/lib/libprop/prop_array.c
--- a/common/lib/libprop/prop_array.c   Fri Jul 27 09:09:05 2012 +0000
+++ b/common/lib/libprop/prop_array.c   Fri Jul 27 09:10:59 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_array.c,v 1.20 2008/08/11 05:54:21 christos Exp $ */
+/*     $NetBSD: prop_array.c,v 1.21 2012/07/27 09:10:59 pooka Exp $    */
 
 /*-
  * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
@@ -29,8 +29,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "prop_object_impl.h"
 #include <prop/prop_array.h>
-#include "prop_object_impl.h"
 
 #if !defined(_KERNEL) && !defined(_STANDALONE)
 #include <errno.h>
@@ -340,7 +340,7 @@
 _prop_array_iterator_next_object(void *v)
 {
        struct _prop_array_iterator *pai = v;
-       prop_array_t pa __unused = pai->pai_base.pi_obj;
+       prop_array_t pa _PROP_ARG_UNUSED = pai->pai_base.pi_obj;
        prop_object_t po;
 
        _PROP_ASSERT(prop_object_is_array(pa));
@@ -367,7 +367,7 @@
 _prop_array_iterator_reset(void *v)
 {
        struct _prop_array_iterator *pai = v;
-       prop_array_t pa __unused = pai->pai_base.pi_obj;
+       prop_array_t pa _PROP_ARG_UNUSED = pai->pai_base.pi_obj;
 
        _PROP_ASSERT(prop_object_is_array(pa));
 
diff -r 3dd7168d2ec0 -r d4b15f0997da common/lib/libprop/prop_array_util.c
--- a/common/lib/libprop/prop_array_util.c      Fri Jul 27 09:09:05 2012 +0000
+++ b/common/lib/libprop/prop_array_util.c      Fri Jul 27 09:10:59 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_array_util.c,v 1.3 2011/03/24 17:05:39 bouyer Exp $       */
+/*     $NetBSD: prop_array_util.c,v 1.4 2012/07/27 09:10:59 pooka Exp $        */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -38,8 +38,8 @@
  * exactly what we're doing here.
  */
 
+#include "prop_object_impl.h" /* hide kernel vs. not-kernel vs. standalone */
 #include <prop/proplib.h>
-#include "prop_object_impl.h" /* hide kernel vs. not-kernel vs. standalone */
 
 bool
 prop_array_get_bool(prop_array_t array,
diff -r 3dd7168d2ec0 -r d4b15f0997da common/lib/libprop/prop_dictionary.c
--- a/common/lib/libprop/prop_dictionary.c      Fri Jul 27 09:09:05 2012 +0000
+++ b/common/lib/libprop/prop_dictionary.c      Fri Jul 27 09:10:59 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_dictionary.c,v 1.37 2011/04/20 19:40:00 martin Exp $      */
+/*     $NetBSD: prop_dictionary.c,v 1.38 2012/07/27 09:10:59 pooka Exp $       */
 
 /*-
  * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
@@ -29,10 +29,10 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "prop_object_impl.h"
 #include <prop/prop_array.h>
 #include <prop/prop_dictionary.h>
 #include <prop/prop_string.h>
-#include "prop_object_impl.h"
 #include "prop_rb_impl.h"
 
 #if !defined(_KERNEL) && !defined(_STANDALONE)
@@ -173,7 +173,7 @@
 
 static int
 /*ARGSUSED*/
-_prop_dict_keysym_rb_compare_nodes(void *ctx __unused,
+_prop_dict_keysym_rb_compare_nodes(void *ctx _PROP_ARG_UNUSED,
                                   const void *n1, const void *n2)
 {
        const struct _prop_dictionary_keysym *pdk1 = n1;
@@ -184,7 +184,7 @@
 
 static int
 /*ARGSUSED*/
-_prop_dict_keysym_rb_compare_key(void *ctx __unused,
+_prop_dict_keysym_rb_compare_key(void *ctx _PROP_ARG_UNUSED,
                                 const void *n, const void *v)
 {
        const struct _prop_dictionary_keysym *pdk = n;
@@ -628,7 +628,7 @@
 _prop_dictionary_iterator_next_object(void *v)
 {
        struct _prop_dictionary_iterator *pdi = v;
-       prop_dictionary_t pd __unused = pdi->pdi_base.pi_obj;
+       prop_dictionary_t pd _PROP_ARG_UNUSED = pdi->pdi_base.pi_obj;
        prop_dictionary_keysym_t pdk;
 
        _PROP_ASSERT(prop_object_is_dictionary(pd));
@@ -655,7 +655,7 @@
 _prop_dictionary_iterator_reset(void *v)
 {
        struct _prop_dictionary_iterator *pdi = v;
-       prop_dictionary_t pd __unused = pdi->pdi_base.pi_obj;
+       prop_dictionary_t pd _PROP_ARG_UNUSED = pdi->pdi_base.pi_obj;
 
        _PROP_RWLOCK_RDLOCK(pd->pd_rwlock);
        _prop_dictionary_iterator_reset_locked(pdi);
diff -r 3dd7168d2ec0 -r d4b15f0997da common/lib/libprop/prop_dictionary_util.c
--- a/common/lib/libprop/prop_dictionary_util.c Fri Jul 27 09:09:05 2012 +0000
+++ b/common/lib/libprop/prop_dictionary_util.c Fri Jul 27 09:10:59 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_dictionary_util.c,v 1.4 2011/03/24 17:05:39 bouyer Exp $  */
+/*     $NetBSD: prop_dictionary_util.c,v 1.5 2012/07/27 09:10:59 pooka Exp $   */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -38,8 +38,8 @@
  * exactly what we're doing here.
  */
 
+#include "prop_object_impl.h"  /* only to hide kernel vs. not-kernel */
 #include <prop/proplib.h>
-#include "prop_object_impl.h"  /* only to hide kernel vs. not-kernel */
 
 bool
 prop_dictionary_get_dict(prop_dictionary_t dict, const char *key, prop_dictionary_t *dp)
diff -r 3dd7168d2ec0 -r d4b15f0997da common/lib/libprop/prop_ingest.c
--- a/common/lib/libprop/prop_ingest.c  Fri Jul 27 09:09:05 2012 +0000
+++ b/common/lib/libprop/prop_ingest.c  Fri Jul 27 09:10:59 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_ingest.c,v 1.3 2008/04/28 20:22:53 martin Exp $   */
+/*     $NetBSD: prop_ingest.c,v 1.4 2012/07/27 09:10:59 pooka Exp $    */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -29,8 +29,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "prop_object_impl.h"
 #include <prop/proplib.h>
-#include "prop_object_impl.h"
 
 struct _prop_ingest_context {
        prop_ingest_error_t     pic_error;
diff -r 3dd7168d2ec0 -r d4b15f0997da common/lib/libprop/prop_number.c
--- a/common/lib/libprop/prop_number.c  Fri Jul 27 09:09:05 2012 +0000
+++ b/common/lib/libprop/prop_number.c  Fri Jul 27 09:10:59 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_number.c,v 1.23 2010/09/24 22:51:52 rmind Exp $   */
+/*     $NetBSD: prop_number.c,v 1.24 2012/07/27 09:10:59 pooka Exp $   */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -119,7 +119,7 @@
 
 static int
 /*ARGSUSED*/
-_prop_number_rb_compare_nodes(void *ctx __unused,
+_prop_number_rb_compare_nodes(void *ctx _PROP_ARG_UNUSED,
                              const void *n1, const void *n2)
 {
        const struct _prop_number *pn1 = n1;
@@ -130,7 +130,8 @@
 
 static int
 /*ARGSUSED*/
-_prop_number_rb_compare_key(void *ctx __unused, const void *n, const void *v)
+_prop_number_rb_compare_key(void *ctx _PROP_ARG_UNUSED,
+                           const void *n, const void *v)
 {
        const struct _prop_number *pn = n;
        const struct _prop_number_value *pnv = v;
diff -r 3dd7168d2ec0 -r d4b15f0997da common/lib/libprop/prop_object.c
--- a/common/lib/libprop/prop_object.c  Fri Jul 27 09:09:05 2012 +0000
+++ b/common/lib/libprop/prop_object.c  Fri Jul 27 09:10:59 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_object.c,v 1.27 2011/04/20 20:00:07 martin Exp $  */
+/*     $NetBSD: prop_object.c,v 1.28 2012/07/27 09:10:59 pooka Exp $   */
 
 /*-
  * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
@@ -29,8 +29,12 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "prop_object_impl.h"
 #include <prop/prop_object.h>
-#include "prop_object_impl.h"
+
+#ifdef _PROP_NEED_REFCNT_MTX
+static pthread_mutex_t _prop_refcnt_mtx = PTHREAD_MUTEX_INITIALIZER;
+#endif /* _PROP_NEED_REFCNT_MTX */
 
 #if !defined(_KERNEL) && !defined(_STANDALONE)
 #include <sys/mman.h>
@@ -40,7 +44,6 @@
 #include <limits.h>
 #include <unistd.h>
 #endif
-#include <sys/atomic.h>
 
 #ifdef _STANDALONE
 void *
@@ -853,10 +856,14 @@
         * and create the temporary file.
         */
        _prop_object_externalize_file_dirname(fname, tname);
-       if (strlcat(tname, "/.plistXXXXXX", sizeof(tname)) >= sizeof(tname)) {
+#define PLISTTMP "/.plistXXXXXX"
+       if (strlen(tname) + strlen(PLISTTMP) >= sizeof(tname)) {
                errno = ENAMETOOLONG;
                return (false);
        }
+       strcat(tname, PLISTTMP);
+#undef PLISTTMP
+
        if ((fd = mkstemp(tname)) == -1)
                return (false);
 
@@ -982,7 +989,7 @@
        struct _prop_object *po = obj;
        uint32_t ncnt;
 
-       ncnt = atomic_inc_32_nv(&po->po_refcnt);
+       _PROP_ATOMIC_INC32_NV(&po->po_refcnt, ncnt);
        _PROP_ASSERT(ncnt != 0);
 }
 
@@ -1014,7 +1021,7 @@
                unlock = po->po_type->pot_unlock;
                
                /* Dance a bit to make sure we always get the non-racy ocnt */
-               ocnt = atomic_dec_32_nv(&po->po_refcnt);
+               _PROP_ATOMIC_DEC32_NV(&po->po_refcnt, ocnt);
                ocnt++;
                _PROP_ASSERT(ocnt != 0);
 
@@ -1036,7 +1043,7 @@
                        unlock();
                
                parent = po;
-               atomic_inc_32(&po->po_refcnt);
+               _PROP_ATOMIC_INC32(&po->po_refcnt);
        }
        _PROP_ASSERT(parent);
        /* One object was just freed. */
@@ -1073,7 +1080,7 @@
                        /* Save pointer to object unlock function */
                        unlock = po->po_type->pot_unlock;
                        
-                       ocnt = atomic_dec_32_nv(&po->po_refcnt);
+                       _PROP_ATOMIC_DEC32_NV(&po->po_refcnt, ocnt);
                        ocnt++;
                        _PROP_ASSERT(ocnt != 0);
 
@@ -1092,7 +1099,7 @@
                        if (ret == _PROP_OBJECT_FREE_DONE)
                                break;
                        
-                       atomic_inc_32(&po->po_refcnt);
+                       _PROP_ATOMIC_INC32(&po->po_refcnt);
                } while (ret == _PROP_OBJECT_FREE_RECURSE);
                if (ret == _PROP_OBJECT_FREE_FAILED)
                        prop_object_release_emergency(obj);
diff -r 3dd7168d2ec0 -r d4b15f0997da common/lib/libprop/prop_object_impl.h
--- a/common/lib/libprop/prop_object_impl.h     Fri Jul 27 09:09:05 2012 +0000
+++ b/common/lib/libprop/prop_object_impl.h     Fri Jul 27 09:10:59 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: prop_object_impl.h,v 1.30 2009/09/13 18:45:10 pooka Exp $      */
+/*     $NetBSD: prop_object_impl.h,v 1.31 2012/07/27 09:10:59 pooka Exp $      */
 
 /*-
  * Copyright (c) 2006 The NetBSD Foundation, Inc.
@@ -293,6 +293,13 @@
 #define _PROP_ONCE_DECL(x)             static ONCE_DECL(x);
 #define _PROP_ONCE_RUN(x,f)            RUN_ONCE(&(x), f)



Home | Main Index | Thread Index | Old Index