9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff/*
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews * Copyright (C) 1999-2001, 2004, 2005, 2007, 2011, 2012, 2016 Internet Systems Consortium, Inc. ("ISC")
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence *
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/.
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff */
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id$ */
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein/*! \file */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff#include <config.h>
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff#include <isc/mutexblock.h>
a44038277a2900c5e4813657a85032b5f09281eaBrian Wellington#include <isc/util.h>
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graffisc_result_t
31c0e4ba054cfc36472a6f1aa7924be18833045eDavid Lawrenceisc_mutexblock_init(isc_mutex_t *block, unsigned int count) {
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff isc_result_t result;
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff unsigned int i;
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson for (i = 0; i < count; i++) {
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff result = isc_mutex_init(&block[i]);
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff if (result != ISC_R_SUCCESS) {
3975f627fe9c0d3aa02ed135070e3253357daad9Mark Andrews while (i > 0U) {
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff i--;
3975f627fe9c0d3aa02ed135070e3253357daad9Mark Andrews DESTROYLOCK(&block[i]);
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff }
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff return (result);
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff }
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff }
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff return (ISC_R_SUCCESS);
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff}
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graffisc_result_t
31c0e4ba054cfc36472a6f1aa7924be18833045eDavid Lawrenceisc_mutexblock_destroy(isc_mutex_t *block, unsigned int count) {
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff isc_result_t result;
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff unsigned int i;
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson for (i = 0; i < count; i++) {
9ce781741ab32ce80c33a1f856d58691276310a0Brian Wellington result = isc_mutex_destroy(&block[i]);
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff if (result != ISC_R_SUCCESS)
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff return (result);
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff }
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff return (ISC_R_SUCCESS);
9c91aa26411a449f26cf5e0b7fb588f8a71977a8Michael Graff}