1 /*
2 * pthread_mutexattr_setrobust.c
3 *
4 * Description:
5 * This translation unit implements mutual exclusion (mutex) primitives.
6 *
7 * --------------------------------------------------------------------------
8 *
9 * Pthreads-win32 - POSIX Threads Library for Win32
10 * Copyright(C) 1998 John E. Bossom
11 * Copyright(C) 1999,2005 Pthreads-win32 contributors
12 *
13 * Contact Email: rpj@callisto.canberra.edu.au
14 *
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
20 *
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.
25 *
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.
30 *
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
35 */
36
37 #include "pthread.h"
38 #include "implement.h"
39
40
41 int
pthread_mutexattr_setrobust(pthread_mutexattr_t * attr,int robust)42 pthread_mutexattr_setrobust (pthread_mutexattr_t * attr, int robust)
43 /*
44 * ------------------------------------------------------
45 *
46 * DOCPUBLIC
47 * The pthread_mutexattr_setrobust() and
48 * pthread_mutexattr_getrobust() functions respectively set and
49 * get the mutex robust attribute. This attribute is set in the
50 * robust parameter to these functions.
51 *
52 * PARAMETERS
53 * attr
54 * pointer to an instance of pthread_mutexattr_t
55 *
56 * robust
57 * must be one of:
58 *
59 * PTHREAD_MUTEX_STALLED
60 *
61 * PTHREAD_MUTEX_ROBUST
62 *
63 * DESCRIPTION
64 * The pthread_mutexattr_setrobust() and
65 * pthread_mutexattr_getrobust() functions respectively set and
66 * get the mutex robust attribute. This attribute is set in the
67 * robust parameter to these functions. The default value of the
68 * robust attribute is PTHREAD_MUTEX_STALLED.
69 *
70 * The robustness of mutex is contained in the robustness attribute
71 * of the mutex attributes. Valid mutex robustness values are:
72 *
73 * PTHREAD_MUTEX_STALLED
74 * No special actions are taken if the owner of the mutex is
75 * terminated while holding the mutex lock. This can lead to
76 * deadlocks if no other thread can unlock the mutex.
77 * This is the default value.
78 *
79 * PTHREAD_MUTEX_ROBUST
80 * If the process containing the owning thread of a robust mutex
81 * terminates while holding the mutex lock, the next thread that
82 * acquires the mutex shall be notified about the termination by
83 * the return value [EOWNERDEAD] from the locking function. If the
84 * owning thread of a robust mutex terminates while holding the mutex
85 * lock, the next thread that acquires the mutex may be notified
86 * about the termination by the return value [EOWNERDEAD]. The
87 * notified thread can then attempt to mark the state protected by
88 * the mutex as consistent again by a call to
89 * pthread_mutex_consistent(). After a subsequent successful call to
90 * pthread_mutex_unlock(), the mutex lock shall be released and can
91 * be used normally by other threads. If the mutex is unlocked without
92 * a call to pthread_mutex_consistent(), it shall be in a permanently
93 * unusable state and all attempts to lock the mutex shall fail with
94 * the error [ENOTRECOVERABLE]. The only permissible operation on such
95 * a mutex is pthread_mutex_destroy().
96 *
97 * RESULTS
98 * 0 successfully set attribute,
99 * EINVAL 'attr' or 'robust' is invalid,
100 *
101 * ------------------------------------------------------
102 */
103 {
104 int result = EINVAL;
105
106 if ((attr != NULL && *attr != NULL))
107 {
108 switch (robust)
109 {
110 case PTHREAD_MUTEX_STALLED:
111 case PTHREAD_MUTEX_ROBUST:
112 (*attr)->robustness = robust;
113 result = 0;
114 break;
115 }
116 }
117
118 return (result);
119 } /* pthread_mutexattr_setrobust */
120