mutex.h revision 9c3531d72aeaad6c5f01efe6a1c82023e1379e4d
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 *
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
1633838b8255282d10af15c5c84cee5a51466712Bob Halley * SOFTWARE.
1633838b8255282d10af15c5c84cee5a51466712Bob Halley */
9a4ce0c25809073f31226faa6ed94c70474cf363Bob Halley
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence/* $Id: mutex.h,v 1.14 2000/06/22 21:58:24 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 */