mutex.h revision 15a44745412679c30a6d022733925af70a38b715
1633838b8255282d10af15c5c84cee5a51466712Bob Halley/*
49dbdb0186eb23d87d685b96eaefa9ec3c71d9b8David Lawrence * Copyright (C) 1998-2000 Internet Software Consortium.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley *
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * Permission to use, copy, modify, and distribute this software for any
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * purpose with or without fee is hereby granted, provided that the above
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * copyright notice and this permission notice appear in all copies.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley *
15a44745412679c30a6d022733925af70a38b715David Lawrence * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
15a44745412679c30a6d022733925af70a38b715David Lawrence * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
15a44745412679c30a6d022733925af70a38b715David Lawrence * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
15a44745412679c30a6d022733925af70a38b715David Lawrence * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
15a44745412679c30a6d022733925af70a38b715David Lawrence * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
15a44745412679c30a6d022733925af70a38b715David Lawrence * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley */
9a4ce0c25809073f31226faa6ed94c70474cf363Bob Halley
15a44745412679c30a6d022733925af70a38b715David Lawrence/* $Id: mutex.h,v 1.15 2000/07/27 09:52:32 tale Exp $ */
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley#ifndef ISC_MUTEX_H
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley#define ISC_MUTEX_H 1
9a4ce0c25809073f31226faa6ed94c70474cf363Bob Halley
9a4ce0c25809073f31226faa6ed94c70474cf363Bob Halley#include <pthread.h>
9a4ce0c25809073f31226faa6ed94c70474cf363Bob Halley
9c4f33b6718407e94d50dbfb4977e16d3f83de9dDavid Lawrence#include <isc/result.h> /* for ISC_R_ codes */
9c4f33b6718407e94d50dbfb4977e16d3f83de9dDavid Lawrence
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halleytypedef pthread_mutex_t isc_mutex_t;
9a4ce0c25809073f31226faa6ed94c70474cf363Bob Halley
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley/* XXX We could do fancier error handling... */
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley#define isc_mutex_init(mp) \
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley ((pthread_mutex_init((mp), NULL) == 0) ? \
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley ISC_R_SUCCESS : ISC_R_UNEXPECTED)
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley#define isc_mutex_lock(mp) \
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley ((pthread_mutex_lock((mp)) == 0) ? \
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley ISC_R_SUCCESS : ISC_R_UNEXPECTED)
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley#define isc_mutex_unlock(mp) \
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley ((pthread_mutex_unlock((mp)) == 0) ? \
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley ISC_R_SUCCESS : ISC_R_UNEXPECTED)
f671a5c51cc59e266620c0c4026b054908fdd80cBob Halley#define isc_mutex_trylock(mp) \
e4b9761b0ef03597c35d1ef1d86e12514c621f90Michael Graff ((pthread_mutex_trylock((mp)) == 0) ? \
f671a5c51cc59e266620c0c4026b054908fdd80cBob Halley ISC_R_SUCCESS : ISC_R_LOCKBUSY)
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley#define isc_mutex_destroy(mp) \
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley ((pthread_mutex_destroy((mp)) == 0) ? \
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley ISC_R_SUCCESS : ISC_R_UNEXPECTED)
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley
bf6d2e39124ab3d51c253f7acad9a4abef059be6Bob Halley#endif /* ISC_MUTEX_H */