Home | History | Annotate | Line # | Download | only in libprop
prop_object_impl.h revision 1.11.4.1.2.1
      1  1.11.4.1.2.1       snj /*	$NetBSD: prop_object_impl.h,v 1.11.4.1.2.1 2008/11/30 23:53:04 snj Exp $	*/
      2           1.1   thorpej 
      3           1.1   thorpej /*-
      4           1.1   thorpej  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5           1.1   thorpej  * All rights reserved.
      6           1.1   thorpej  *
      7           1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8           1.1   thorpej  * by Jason R. Thorpe.
      9           1.1   thorpej  *
     10           1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     11           1.1   thorpej  * modification, are permitted provided that the following conditions
     12           1.1   thorpej  * are met:
     13           1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     14           1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     15           1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16           1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17           1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     18           1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     19           1.1   thorpej  *    must display the following acknowledgement:
     20           1.1   thorpej  *      This product includes software developed by the NetBSD
     21           1.1   thorpej  *      Foundation, Inc. and its contributors.
     22           1.1   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23           1.1   thorpej  *    contributors may be used to endorse or promote products derived
     24           1.1   thorpej  *    from this software without specific prior written permission.
     25           1.1   thorpej  *
     26           1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27           1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28           1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29           1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30           1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31           1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32           1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33           1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34           1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35           1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36           1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     37           1.1   thorpej  */
     38           1.1   thorpej 
     39           1.1   thorpej #ifndef _PROPLIB_PROP_OBJECT_IMPL_H_
     40           1.1   thorpej #define	_PROPLIB_PROP_OBJECT_IMPL_H_
     41           1.1   thorpej 
     42           1.5   thorpej #if defined(_KERNEL) || defined(_STANDALONE)
     43           1.5   thorpej #include <lib/libkern/libkern.h>
     44           1.5   thorpej #else
     45           1.5   thorpej #include <inttypes.h>
     46           1.5   thorpej #endif
     47           1.5   thorpej 
     48      1.11.4.1   xtraeme #include "prop_stack.h"
     49      1.11.4.1   xtraeme 
     50           1.1   thorpej struct _prop_object_externalize_context {
     51           1.1   thorpej 	char *		poec_buf;		/* string buffer */
     52           1.1   thorpej 	size_t		poec_capacity;		/* capacity of buffer */
     53           1.1   thorpej 	size_t		poec_len;		/* current length of string */
     54           1.1   thorpej 	unsigned int	poec_depth;		/* nesting depth */
     55           1.1   thorpej };
     56           1.1   thorpej 
     57      1.11.4.1   xtraeme bool	_prop_object_externalize_start_tag(
     58           1.1   thorpej 				struct _prop_object_externalize_context *,
     59           1.1   thorpej 				const char *);
     60      1.11.4.1   xtraeme bool	_prop_object_externalize_end_tag(
     61           1.1   thorpej 				struct _prop_object_externalize_context *,
     62           1.1   thorpej 				const char *);
     63      1.11.4.1   xtraeme bool	_prop_object_externalize_empty_tag(
     64           1.1   thorpej 				struct _prop_object_externalize_context *,
     65           1.1   thorpej 				const char *);
     66      1.11.4.1   xtraeme bool	_prop_object_externalize_append_cstring(
     67           1.1   thorpej 				struct _prop_object_externalize_context *,
     68           1.1   thorpej 				const char *);
     69      1.11.4.1   xtraeme bool	_prop_object_externalize_append_encoded_cstring(
     70           1.1   thorpej 				struct _prop_object_externalize_context *,
     71           1.1   thorpej 				const char *);
     72      1.11.4.1   xtraeme bool	_prop_object_externalize_append_char(
     73           1.1   thorpej 				struct _prop_object_externalize_context *,
     74           1.1   thorpej 				unsigned char);
     75      1.11.4.1   xtraeme bool	_prop_object_externalize_header(
     76           1.4   thorpej 				struct _prop_object_externalize_context *);
     77      1.11.4.1   xtraeme bool	_prop_object_externalize_footer(
     78           1.4   thorpej 				struct _prop_object_externalize_context *);
     79           1.1   thorpej 
     80           1.1   thorpej struct _prop_object_externalize_context *
     81           1.1   thorpej 		_prop_object_externalize_context_alloc(void);
     82           1.1   thorpej void		_prop_object_externalize_context_free(
     83           1.1   thorpej 				struct _prop_object_externalize_context *);
     84           1.1   thorpej 
     85           1.1   thorpej typedef enum {
     86           1.1   thorpej 	_PROP_TAG_TYPE_START,			/* e.g. <dict> */
     87           1.1   thorpej 	_PROP_TAG_TYPE_END,			/* e.g. </dict> */
     88           1.1   thorpej 	_PROP_TAG_TYPE_EITHER
     89           1.1   thorpej } _prop_tag_type_t;
     90           1.1   thorpej 
     91           1.1   thorpej struct _prop_object_internalize_context {
     92           1.1   thorpej 	const char *poic_xml;
     93           1.1   thorpej 	const char *poic_cp;
     94           1.1   thorpej 
     95           1.1   thorpej 	const char *poic_tag_start;
     96           1.1   thorpej 
     97           1.1   thorpej 	const char *poic_tagname;
     98           1.1   thorpej 	size_t      poic_tagname_len;
     99           1.1   thorpej 	const char *poic_tagattr;
    100           1.1   thorpej 	size_t      poic_tagattr_len;
    101           1.1   thorpej 	const char *poic_tagattrval;
    102           1.1   thorpej 	size_t      poic_tagattrval_len;
    103           1.1   thorpej 
    104      1.11.4.1   xtraeme 	bool   poic_is_empty_element;
    105           1.1   thorpej 	_prop_tag_type_t poic_tag_type;
    106           1.1   thorpej };
    107           1.1   thorpej 
    108      1.11.4.1   xtraeme enum {
    109      1.11.4.1   xtraeme 	_PROP_OBJECT_FREE_DONE,
    110      1.11.4.1   xtraeme 	_PROP_OBJECT_FREE_RECURSE,
    111      1.11.4.1   xtraeme 	_PROP_OBJECT_FREE_FAILED
    112      1.11.4.1   xtraeme };
    113      1.11.4.1   xtraeme 
    114      1.11.4.1   xtraeme enum {
    115      1.11.4.1   xtraeme 	_PROP_OBJECT_EQUALS_FALSE,
    116      1.11.4.1   xtraeme 	_PROP_OBJECT_EQUALS_TRUE,
    117      1.11.4.1   xtraeme 	_PROP_OBJECT_EQUALS_RECURSE
    118      1.11.4.1   xtraeme };
    119      1.11.4.1   xtraeme 
    120           1.1   thorpej #define	_PROP_EOF(c)		((c) == '\0')
    121           1.1   thorpej #define	_PROP_ISSPACE(c)	\
    122      1.11.4.1   xtraeme 	((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || \
    123      1.11.4.1   xtraeme 	 _PROP_EOF(c))
    124           1.1   thorpej 
    125           1.1   thorpej #define	_PROP_TAG_MATCH(ctx, t)					\
    126           1.1   thorpej 	_prop_object_internalize_match((ctx)->poic_tagname,	\
    127           1.1   thorpej 				       (ctx)->poic_tagname_len,	\
    128           1.1   thorpej 				       (t), strlen(t))
    129           1.1   thorpej 
    130           1.1   thorpej #define	_PROP_TAGATTR_MATCH(ctx, a)				\
    131           1.1   thorpej 	_prop_object_internalize_match((ctx)->poic_tagattr,	\
    132           1.1   thorpej 				       (ctx)->poic_tagattr_len,	\
    133           1.1   thorpej 				       (a), strlen(a))
    134           1.1   thorpej 
    135           1.1   thorpej #define	_PROP_TAGATTRVAL_MATCH(ctx, a)				  \
    136           1.1   thorpej 	_prop_object_internalize_match((ctx)->poic_tagattrval,	  \
    137           1.1   thorpej 				       (ctx)->poic_tagattrval_len,\
    138           1.1   thorpej 				       (a), strlen(a))
    139           1.1   thorpej 
    140      1.11.4.1   xtraeme bool	_prop_object_internalize_find_tag(
    141           1.1   thorpej 				struct _prop_object_internalize_context *,
    142           1.1   thorpej 				const char *, _prop_tag_type_t);
    143      1.11.4.1   xtraeme bool	_prop_object_internalize_match(const char *, size_t,
    144           1.1   thorpej 					       const char *, size_t);
    145           1.1   thorpej prop_object_t	_prop_object_internalize_by_tag(
    146           1.1   thorpej 				struct _prop_object_internalize_context *);
    147      1.11.4.1   xtraeme bool	_prop_object_internalize_decode_string(
    148           1.1   thorpej 				struct _prop_object_internalize_context *,
    149           1.1   thorpej 				char *, size_t, size_t *, const char **);
    150      1.11.4.1   xtraeme prop_object_t	_prop_generic_internalize(const char *, const char *);
    151           1.1   thorpej 
    152           1.1   thorpej struct _prop_object_internalize_context *
    153           1.1   thorpej 		_prop_object_internalize_context_alloc(const char *);
    154           1.1   thorpej void		_prop_object_internalize_context_free(
    155           1.1   thorpej 				struct _prop_object_internalize_context *);
    156           1.1   thorpej 
    157           1.4   thorpej #if !defined(_KERNEL) && !defined(_STANDALONE)
    158      1.11.4.1   xtraeme bool	_prop_object_externalize_write_file(const char *,
    159           1.4   thorpej 						    const char *, size_t);
    160           1.4   thorpej 
    161           1.4   thorpej struct _prop_object_internalize_mapped_file {
    162           1.4   thorpej 	char *	poimf_xml;
    163           1.4   thorpej 	size_t	poimf_mapsize;
    164           1.4   thorpej };
    165           1.4   thorpej 
    166           1.4   thorpej struct _prop_object_internalize_mapped_file *
    167           1.4   thorpej 		_prop_object_internalize_map_file(const char *);
    168           1.4   thorpej void		_prop_object_internalize_unmap_file(
    169           1.4   thorpej 				struct _prop_object_internalize_mapped_file *);
    170           1.4   thorpej #endif /* !_KERNEL && !_STANDALONE */
    171           1.4   thorpej 
    172      1.11.4.1   xtraeme typedef bool (*prop_object_internalizer_t)(prop_stack_t, prop_object_t *,
    173      1.11.4.1   xtraeme     struct _prop_object_internalize_context *);
    174      1.11.4.1   xtraeme typedef bool (*prop_object_internalizer_continue_t)(prop_stack_t, prop_object_t *,
    175      1.11.4.1   xtraeme     struct _prop_object_internalize_context *, void *, prop_object_t);
    176      1.11.4.1   xtraeme 
    177           1.1   thorpej 	/* These are here because they're required by shared code. */
    178      1.11.4.1   xtraeme bool	_prop_array_internalize(prop_stack_t, prop_object_t *,
    179      1.11.4.1   xtraeme     struct _prop_object_internalize_context *);
    180      1.11.4.1   xtraeme bool	_prop_bool_internalize(prop_stack_t, prop_object_t *,
    181      1.11.4.1   xtraeme     struct _prop_object_internalize_context *);
    182      1.11.4.1   xtraeme bool	_prop_data_internalize(prop_stack_t, prop_object_t *,
    183      1.11.4.1   xtraeme     struct _prop_object_internalize_context *);
    184      1.11.4.1   xtraeme bool	_prop_dictionary_internalize(prop_stack_t, prop_object_t *,
    185      1.11.4.1   xtraeme     struct _prop_object_internalize_context *);
    186      1.11.4.1   xtraeme bool	_prop_number_internalize(prop_stack_t, prop_object_t *,
    187      1.11.4.1   xtraeme     struct _prop_object_internalize_context *);
    188      1.11.4.1   xtraeme bool	_prop_string_internalize(prop_stack_t, prop_object_t *,
    189      1.11.4.1   xtraeme     struct _prop_object_internalize_context *);
    190           1.1   thorpej 
    191           1.2   thorpej struct _prop_object_type {
    192      1.11.4.1   xtraeme 	/* type indicator */
    193      1.11.4.1   xtraeme 	uint32_t	pot_type;
    194      1.11.4.1   xtraeme 	/* func to free object */
    195      1.11.4.1   xtraeme 	int		(*pot_free)(prop_stack_t, prop_object_t *);
    196      1.11.4.1   xtraeme 	/*
    197      1.11.4.1   xtraeme 	 * func to free the child returned by pot_free with stack == NULL.
    198      1.11.4.1   xtraeme 	 *
    199      1.11.4.1   xtraeme 	 * Must be implemented if pot_free can return anything other than
    200      1.11.4.1   xtraeme 	 * _PROP_OBJECT_FREE_DONE.
    201      1.11.4.1   xtraeme 	 */
    202      1.11.4.1   xtraeme 	void	(*pot_emergency_free)(prop_object_t);
    203      1.11.4.1   xtraeme 	/* func to externalize object */
    204      1.11.4.1   xtraeme 	bool	(*pot_extern)(struct _prop_object_externalize_context *,
    205      1.11.4.1   xtraeme 			      void *);
    206      1.11.4.1   xtraeme 	/* func to test quality */
    207      1.11.4.1   xtraeme 	bool	(*pot_equals)(prop_object_t, prop_object_t,
    208      1.11.4.1   xtraeme 			      void **, void **,
    209      1.11.4.1   xtraeme 			      prop_object_t *, prop_object_t *);
    210      1.11.4.1   xtraeme 	/*
    211      1.11.4.1   xtraeme 	 * func to finish equality iteration.
    212      1.11.4.1   xtraeme 	 *
    213      1.11.4.1   xtraeme 	 * Must be implemented if pot_equals can return
    214      1.11.4.1   xtraeme 	 * _PROP_OBJECT_EQUALS_RECURSE
    215      1.11.4.1   xtraeme 	 */
    216      1.11.4.1   xtraeme 	void	(*pot_equals_finish)(prop_object_t, prop_object_t);
    217  1.11.4.1.2.1       snj 	void    (*pot_lock)(void);
    218  1.11.4.1.2.1       snj 	void    (*pot_unlock)(void);
    219           1.2   thorpej };
    220           1.2   thorpej 
    221           1.1   thorpej struct _prop_object {
    222           1.2   thorpej 	const struct _prop_object_type *po_type;/* type descriptor */
    223           1.1   thorpej 	uint32_t	po_refcnt;		/* reference count */
    224           1.1   thorpej };
    225           1.1   thorpej 
    226           1.2   thorpej void	_prop_object_init(struct _prop_object *,
    227           1.2   thorpej 			  const struct _prop_object_type *);
    228           1.1   thorpej void	_prop_object_fini(struct _prop_object *);
    229           1.1   thorpej 
    230           1.1   thorpej struct _prop_object_iterator {
    231           1.1   thorpej 	prop_object_t	(*pi_next_object)(void *);
    232           1.1   thorpej 	void		(*pi_reset)(void *);
    233           1.1   thorpej 	prop_object_t	pi_obj;
    234           1.1   thorpej 	uint32_t	pi_version;
    235           1.1   thorpej };
    236           1.1   thorpej 
    237           1.1   thorpej #if defined(_KERNEL)
    238           1.1   thorpej 
    239           1.1   thorpej /*
    240           1.1   thorpej  * proplib in the kernel...
    241           1.1   thorpej  */
    242           1.1   thorpej 
    243           1.6   thorpej #include <sys/param.h>
    244           1.1   thorpej #include <sys/malloc.h>
    245           1.1   thorpej #include <sys/pool.h>
    246           1.1   thorpej #include <sys/systm.h>
    247           1.3   thorpej #include <sys/lock.h>
    248           1.1   thorpej 
    249           1.1   thorpej #define	_PROP_ASSERT(x)		KASSERT(x)
    250           1.1   thorpej 
    251           1.1   thorpej #define	_PROP_MALLOC(s, t)	malloc((s), (t), M_WAITOK)
    252           1.1   thorpej #define	_PROP_CALLOC(s, t)	malloc((s), (t), M_WAITOK | M_ZERO)
    253           1.2   thorpej #define	_PROP_REALLOC(v, s, t)	realloc((v), (s), (t), M_WAITOK)
    254           1.1   thorpej #define	_PROP_FREE(v, t)	free((v), (t))
    255           1.1   thorpej 
    256           1.1   thorpej #define	_PROP_POOL_GET(p)	pool_get(&(p), PR_WAITOK)
    257           1.1   thorpej #define	_PROP_POOL_PUT(p, v)	pool_put(&(p), (v))
    258           1.1   thorpej 
    259           1.1   thorpej #define	_PROP_POOL_INIT(p, s, d)					\
    260           1.1   thorpej 		POOL_INIT(p, s, 0, 0, 0, d, &pool_allocator_nointr);
    261           1.1   thorpej 
    262           1.1   thorpej #define	_PROP_MALLOC_DEFINE(t, s, l)					\
    263           1.1   thorpej 		MALLOC_DEFINE(t, s, l);
    264           1.1   thorpej 
    265           1.6   thorpej #define	_PROP_MUTEX_DECL_STATIC(x)					\
    266           1.3   thorpej 		static struct simplelock x = SIMPLELOCK_INITIALIZER;
    267           1.3   thorpej #define	_PROP_MUTEX_LOCK(x)	simple_lock(&(x))
    268           1.3   thorpej #define	_PROP_MUTEX_UNLOCK(x)	simple_unlock(&(x))
    269           1.3   thorpej 
    270           1.6   thorpej #define	_PROP_RWLOCK_DECL(x)	struct lock x ;
    271           1.6   thorpej #define	_PROP_RWLOCK_INIT(x)	lockinit(&(x), PZERO, "proprwlk", 0, 0)
    272           1.6   thorpej #define	_PROP_RWLOCK_RDLOCK(x)	lockmgr(&(x), LK_SHARED, NULL)
    273           1.6   thorpej #define	_PROP_RWLOCK_WRLOCK(x)	lockmgr(&(x), LK_EXCLUSIVE, NULL)
    274           1.6   thorpej #define	_PROP_RWLOCK_UNLOCK(x)	lockmgr(&(x), LK_RELEASE, NULL)
    275           1.6   thorpej #define	_PROP_RWLOCK_DESTROY(x)	lockmgr(&(x), LK_DRAIN, NULL)
    276           1.6   thorpej 
    277           1.1   thorpej #elif defined(_STANDALONE)
    278           1.1   thorpej 
    279           1.1   thorpej /*
    280           1.1   thorpej  * proplib in a standalone environment...
    281           1.1   thorpej  */
    282           1.1   thorpej 
    283           1.1   thorpej #include <lib/libsa/stand.h>
    284           1.1   thorpej 
    285           1.1   thorpej void *		_prop_standalone_calloc(size_t);
    286           1.2   thorpej void *		_prop_standalone_realloc(void *, size_t);
    287           1.1   thorpej 
    288           1.1   thorpej #define	_PROP_ASSERT(x)		/* nothing */
    289           1.1   thorpej 
    290           1.1   thorpej #define	_PROP_MALLOC(s, t)	alloc((s))
    291           1.1   thorpej #define	_PROP_CALLOC(s, t)	_prop_standalone_calloc((s))
    292           1.2   thorpej #define	_PROP_REALLOC(v, s, t)	_prop_standalone_realloc((v), (s))
    293           1.1   thorpej #define	_PROP_FREE(v, t)	dealloc((v), 0)		/* XXX */
    294           1.1   thorpej 
    295           1.1   thorpej #define	_PROP_POOL_GET(p)	alloc((p))
    296           1.1   thorpej #define	_PROP_POOL_PUT(p, v)	dealloc((v), (p))
    297           1.1   thorpej 
    298           1.1   thorpej #define	_PROP_POOL_INIT(p, s, d)	static const size_t p = s;
    299           1.1   thorpej 
    300           1.1   thorpej #define	_PROP_MALLOC_DEFINE(t, s, l)	/* nothing */
    301           1.1   thorpej 
    302           1.6   thorpej #define	_PROP_MUTEX_DECL_STATIC(x)	/* nothing */
    303           1.6   thorpej #define	_PROP_MUTEX_LOCK(x)		/* nothing */
    304           1.6   thorpej #define	_PROP_MUTEX_UNLOCK(x)		/* nothing */
    305           1.6   thorpej 
    306           1.6   thorpej #define	_PROP_RWLOCK_DECL(x)	/* nothing */
    307           1.6   thorpej #define	_PROP_RWLOCK_INIT(x)	/* nothing */
    308           1.6   thorpej #define	_PROP_RWLOCK_RDLOCK(x)	/* nothing */
    309           1.6   thorpej #define	_PROP_RWLOCK_WRLOCK(x)	/* nothing */
    310           1.6   thorpej #define	_PROP_RWLOCK_UNLOCK(x)	/* nothing */
    311           1.7       dbj #define	_PROP_RWLOCK_DESTROY(x)	/* nothing */
    312           1.3   thorpej 
    313           1.1   thorpej #else
    314           1.1   thorpej 
    315           1.1   thorpej /*
    316           1.1   thorpej  * proplib in user space...
    317           1.1   thorpej  */
    318           1.1   thorpej 
    319           1.1   thorpej #include <assert.h>
    320           1.1   thorpej #include <string.h>
    321           1.1   thorpej #include <stdio.h>
    322           1.1   thorpej #include <stdlib.h>
    323           1.5   thorpej #include <stddef.h>
    324           1.1   thorpej 
    325           1.8  christos #define	_PROP_ASSERT(x)		/*LINTED*/assert(x)
    326           1.1   thorpej 
    327           1.1   thorpej #define	_PROP_MALLOC(s, t)	malloc((s))
    328          1.11    martin #define	_PROP_CALLOC(s, t)	calloc(1, (s))
    329           1.2   thorpej #define	_PROP_REALLOC(v, s, t)	realloc((v), (s))
    330           1.1   thorpej #define	_PROP_FREE(v, t)	free((v))
    331           1.1   thorpej 
    332           1.1   thorpej #define	_PROP_POOL_GET(p)	malloc((p))
    333           1.1   thorpej #define	_PROP_POOL_PUT(p, v)	free((v))
    334           1.1   thorpej 
    335           1.1   thorpej #define	_PROP_POOL_INIT(p, s, d)	static const size_t p = s;
    336           1.1   thorpej 
    337           1.1   thorpej #define	_PROP_MALLOC_DEFINE(t, s, l)	/* nothing */
    338           1.1   thorpej 
    339           1.3   thorpej #if defined(__NetBSD__) && defined(_LIBPROP)
    340           1.3   thorpej /*
    341           1.3   thorpej  * Use the same mechanism as libc; we get pthread mutexes for threaded
    342           1.3   thorpej  * programs and do-nothing stubs for non-threaded programs.
    343           1.3   thorpej  */
    344           1.3   thorpej #include "reentrant.h"
    345           1.6   thorpej #define	_PROP_MUTEX_DECL_STATIC(x)	static mutex_t x = MUTEX_INITIALIZER;
    346           1.6   thorpej #define	_PROP_MUTEX_LOCK(x)		mutex_lock(&(x))
    347           1.6   thorpej #define	_PROP_MUTEX_UNLOCK(x)		mutex_unlock(&(x))
    348           1.6   thorpej 
    349           1.6   thorpej #define	_PROP_RWLOCK_DECL(x)	rwlock_t x ;
    350           1.6   thorpej #define	_PROP_RWLOCK_INIT(x)	rwlock_init(&(x), NULL)
    351           1.6   thorpej #define	_PROP_RWLOCK_RDLOCK(x)	rwlock_rdlock(&(x))
    352           1.6   thorpej #define	_PROP_RWLOCK_WRLOCK(x)	rwlock_wrlock(&(x))
    353           1.6   thorpej #define	_PROP_RWLOCK_UNLOCK(x)	rwlock_unlock(&(x))
    354           1.6   thorpej #define	_PROP_RWLOCK_DESTROY(x)	rwlock_destroy(&(x))
    355           1.3   thorpej #elif defined(HAVE_NBTOOL_CONFIG_H)
    356           1.3   thorpej /*
    357           1.3   thorpej  * None of NetBSD's build tools are multi-threaded.
    358           1.3   thorpej  */
    359           1.6   thorpej #define	_PROP_MUTEX_DECL_STATIC(x)	/* nothing */
    360           1.6   thorpej #define	_PROP_MUTEX_LOCK(x)		/* nothing */
    361           1.6   thorpej #define	_PROP_MUTEX_UNLOCK(x)		/* nothing */
    362           1.6   thorpej 
    363           1.6   thorpej #define	_PROP_RWLOCK_DECL(x)	/* nothing */
    364           1.6   thorpej #define	_PROP_RWLOCK_INIT(x)	/* nothing */
    365           1.6   thorpej #define	_PROP_RWLOCK_RDLOCK(x)	/* nothing */
    366           1.6   thorpej #define	_PROP_RWLOCK_WRLOCK(x)	/* nothing */
    367           1.6   thorpej #define	_PROP_RWLOCK_UNLOCK(x)	/* nothing */
    368           1.6   thorpej #define	_PROP_RWLOCK_DESTROY(x)	/* nothing */
    369           1.3   thorpej #else
    370           1.3   thorpej /*
    371           1.3   thorpej  * Use pthread mutexes everywhere else.
    372           1.3   thorpej  */
    373           1.3   thorpej #include <pthread.h>
    374           1.6   thorpej #define	_PROP_MUTEX_DECL_STATIC(x)					\
    375           1.3   thorpej 		static pthread_mutex_t x = PTHREAD_MUTEX_INITIALIZER;
    376           1.3   thorpej #define	_PROP_MUTEX_LOCK(x)	pthread_mutex_lock(&(x))
    377           1.3   thorpej #define	_PROP_MUTEX_UNLOCK(x)	pthread_mutex_unlock(&(x))
    378           1.6   thorpej 
    379           1.6   thorpej #define	_PROP_RWLOCK_DECL(x)	pthread_rwlock_t x ;
    380           1.6   thorpej #define	_PROP_RWLOCK_INIT(x)	pthread_rwlock_init(&(x), NULL)
    381           1.6   thorpej #define	_PROP_RWLOCK_RDLOCK(x)	pthread_rwlock_rdlock(&(x))
    382           1.6   thorpej #define	_PROP_RWLOCK_WRLOCK(x)	pthread_rwlock_wrlock(&(x))
    383           1.6   thorpej #define	_PROP_RWLOCK_UNLOCK(x)	pthread_rwlock_unlock(&(x))
    384           1.6   thorpej #define	_PROP_RWLOCK_DESTROY(x)	pthread_rwlock_destroy(&(x))
    385           1.3   thorpej #endif
    386           1.3   thorpej 
    387           1.1   thorpej #endif /* _KERNEL */
    388           1.1   thorpej 
    389           1.9   thorpej /*
    390           1.9   thorpej  * Language features.
    391           1.9   thorpej  */
    392           1.9   thorpej #if defined(__NetBSD__)
    393           1.9   thorpej #include <sys/cdefs.h>
    394           1.9   thorpej #define	_PROP_ARG_UNUSED	__unused
    395           1.9   thorpej #else
    396           1.9   thorpej #define	_PROP_ARG_UNUSED	/* delete */
    397           1.9   thorpej #endif /* __NetBSD__ */
    398           1.9   thorpej 
    399           1.1   thorpej #endif /* _PROPLIB_PROP_OBJECT_IMPL_H_ */
    400