43e68674d49803e1c902d9c717700cf76f9006daMark Andrews/*
8688e7005afed694ca129d00d3cd73b32828804bTinderbox User * Copyright (C) 2005, 2007, 2016, 2017 Internet Systems Consortium, Inc. ("ISC")
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews *
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * file, You can obtain one at http://mozilla.org/MPL/2.0/.
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews */
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater/* $Id: refcount.c,v 1.5 2007/06/19 23:47:17 tbox Exp $ */
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews#include <config.h>
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews#include <stddef.h>
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews#include <isc/mutex.h>
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews#include <isc/refcount.h>
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews#include <isc/result.h>
f44202ab640d22e17b4c74bdad7817622918bd27Mark Andrews#include <isc/util.h>
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews
43e68674d49803e1c902d9c717700cf76f9006daMark Andrewsisc_result_t
43e68674d49803e1c902d9c717700cf76f9006daMark Andrewsisc_refcount_init(isc_refcount_t *ref, unsigned int n) {
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews REQUIRE(ref != NULL);
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews ref->refs = n;
99056063905a9273ec59cf477ae747e0490182b7Mukund Sivaraman#if defined(ISC_PLATFORM_USETHREADS) && !defined(ISC_REFCOUNT_HAVEATOMIC)
9ada5ea35f181032438cb94c391a63b6cd76ceeeMark Andrews return (isc_mutex_init(&ref->lock));
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews#else
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews return (ISC_R_SUCCESS);
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews#endif
43e68674d49803e1c902d9c717700cf76f9006daMark Andrews}