xref: /minix/external/bsd/bind/dist/lib/isc/refcount.c (revision 9f7f0ad0)
1 /*	$NetBSD: refcount.c,v 1.4 2014/12/10 04:37:59 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
5  *
6  * Permission to use, copy, modify, and/or distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
11  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
13  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
15  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 /* Id: refcount.c,v 1.5 2007/06/19 23:47:17 tbox Exp  */
20 
21 #include <config.h>
22 
23 #include <stddef.h>
24 
25 #include <isc/mutex.h>
26 #include <isc/refcount.h>
27 #include <isc/result.h>
28 
29 isc_result_t
30 isc_refcount_init(isc_refcount_t *ref, unsigned int n) {
31 	REQUIRE(ref != NULL);
32 
33 	ref->refs = n;
34 #if defined(ISC_PLATFORM_USETHREADS) && !defined(ISC_PLATFORM_HAVEXADD)
35 	return (isc_mutex_init(&ref->lock));
36 #else
37 	return (ISC_R_SUCCESS);
38 #endif
39 }
40