2 * pthread_mutexattr_settype.c
5 * This translation unit implements mutual exclusion (mutex) primitives.
7 * --------------------------------------------------------------------------
9 * Pthreads-win32 - POSIX Threads Library for Win32
10 * Copyright(C) 1998 John E. Bossom
11 * Copyright(C) 1999,2005 Pthreads-win32 contributors
13 * Contact Email: rpj@callisto.canberra.edu.au
15 * The current list of contributors is contained
16 * in the file CONTRIBUTORS included with the source
17 * code distribution. The list can also be seen at the
18 * following World Wide Web location:
19 * http://sources.redhat.com/pthreads-win32/contributors.html
21 * This library is free software; you can redistribute it and/or
22 * modify it under the terms of the GNU Lesser General Public
23 * License as published by the Free Software Foundation; either
24 * version 2 of the License, or (at your option) any later version.
26 * This library is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
29 * Lesser General Public License for more details.
31 * You should have received a copy of the GNU Lesser General Public
32 * License along with this library in the file COPYING.LIB;
33 * if not, write to the Free Software Foundation, Inc.,
34 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
38 #include "implement.h"
42 pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind)
44 * ------------------------------------------------------
47 * The pthread_mutexattr_settype() and
48 * pthread_mutexattr_gettype() functions respectively set and
49 * get the mutex type attribute. This attribute is set in the
50 * type parameter to these functions.
54 * pointer to an instance of pthread_mutexattr_t
59 * PTHREAD_MUTEX_DEFAULT
61 * PTHREAD_MUTEX_NORMAL
63 * PTHREAD_MUTEX_ERRORCHECK
65 * PTHREAD_MUTEX_RECURSIVE
68 * The pthread_mutexattr_settype() and
69 * pthread_mutexattr_gettype() functions respectively set and
70 * get the mutex type attribute. This attribute is set in the
71 * type parameter to these functions. The default value of the
72 * type attribute is PTHREAD_MUTEX_DEFAULT.
74 * The type of mutex is contained in the type attribute of the
75 * mutex attributes. Valid mutex types include:
77 * PTHREAD_MUTEX_NORMAL
78 * This type of mutex does not detect deadlock. A
79 * thread attempting to relock this mutex without
80 * first unlocking it will deadlock. Attempting to
81 * unlock a mutex locked by a different thread
82 * results in undefined behavior. Attempting to
83 * unlock an unlocked mutex results in undefined
86 * PTHREAD_MUTEX_ERRORCHECK
87 * This type of mutex provides error checking. A
88 * thread attempting to relock this mutex without
89 * first unlocking it will return with an error. A
90 * thread attempting to unlock a mutex which another
91 * thread has locked will return with an error. A
92 * thread attempting to unlock an unlocked mutex will
93 * return with an error.
95 * PTHREAD_MUTEX_DEFAULT
96 * Same as PTHREAD_MUTEX_NORMAL.
98 * PTHREAD_MUTEX_RECURSIVE
99 * A thread attempting to relock this mutex without
100 * first unlocking it will succeed in locking the
101 * mutex. The relocking deadlock which can occur with
102 * mutexes of type PTHREAD_MUTEX_NORMAL cannot occur
103 * with this type of mutex. Multiple locks of this
104 * mutex require the same number of unlocks to
105 * release the mutex before another thread can
106 * acquire the mutex. A thread attempting to unlock a
107 * mutex which another thread has locked will return
108 * with an error. A thread attempting to unlock an
109 * unlocked mutex will return with an error. This
110 * type of mutex is only supported for mutexes whose
111 * process shared attribute is
112 * PTHREAD_PROCESS_PRIVATE.
115 * 0 successfully set attribute,
116 * EINVAL 'attr' or 'type' is invalid,
118 * ------------------------------------------------------
123 if ((attr != NULL && *attr != NULL))
127 case PTHREAD_MUTEX_FAST_NP:
128 case PTHREAD_MUTEX_RECURSIVE_NP:
129 case PTHREAD_MUTEX_ERRORCHECK_NP:
130 (*attr)->kind = kind;
143 } /* pthread_mutexattr_settype */