Debian Codegraph @

libmowgli-2/src/libmowgli/thread/posix_mutexops.c

raw
1 /*
2 * libmowgli: A collection of useful routines for programming.
3 * posix_mutexops.c: POSIX Mutexes.
4 *
5 * Copyright (c) 2011 Wilcox Technologies, LLC <awilcox -at- wilcox-tech.com>
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice is present in all copies.
10 *
11 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
12 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
13 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
14 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
15 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
16 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
17 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
19 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
20 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
21 * POSSIBILITY OF SUCH DAMAGE.
22 */
23
24 #include "mowgli.h"
25 #include "thread/mutex_internal.h"
26
27 #ifndef _WIN32
28
29 /*************
30 * This "default" implementation uses pthreads. Care has been taken to
31 * ensure it runs on POSIX 1003.4a (draft 4, aka DECthreads, aka what OSF/1,
32 * Tru64, Ultrix, CMU Mach, and HP-UX use) as well as POSIX 1003.1c-1995.
33 * As long as you don't try playing with the pthread_attr module or the
34 * scheduler routines (which are non-standard and broken anyway, IMO) then
35 * it should be relatively easy to maintian d4 compatibility without
36 * sacrificing any functionality.
37 *************/
38 # if !defined(MOWGLI_FEATURE_HAVE_NATIVE_MUTEXES)
39
40 static int
41 mowgli_posix_mutex_create(mowgli_mutex_t *mutex)
42 {
43 return pthread_mutex_init(&mutex->mutex, NULL);
44 }
45
46 static int
47 mowgli_posix_mutex_lock(mowgli_mutex_t *mutex)
48 {
49 return pthread_mutex_lock(&mutex->mutex);
50 }
51
52 static int
53 mowgli_posix_mutex_trylock(mowgli_mutex_t *mutex)
54 {
55 return pthread_mutex_trylock(&mutex->mutex);
56 }
57
58 static int
59 mowgli_posix_mutex_unlock(mowgli_mutex_t *mutex)
60 {
61 return pthread_mutex_unlock(&mutex->mutex);
62 }
63
64 static int
65 mowgli_posix_mutex_destroy(mowgli_mutex_t *mutex)
66 {
67 return pthread_mutex_destroy(&mutex->mutex);
68 }
69
70 const mowgli_mutex_ops_t _mowgli_posix_mutex_ops =
71 {
72 .mutex_create = mowgli_posix_mutex_create,
73 .mutex_lock = mowgli_posix_mutex_lock,
74 .mutex_trylock = mowgli_posix_mutex_trylock,
75 .mutex_unlock = mowgli_posix_mutex_unlock,
76 .mutex_destroy = mowgli_posix_mutex_destroy,
77 };
78
79 # endif
80
81 #endif