/[pcsx2_0.9.7]/trunk/3rdparty/w32pthreads/pthread_mutexattr_settype.c
ViewVC logotype

Contents of /trunk/3rdparty/w32pthreads/pthread_mutexattr_settype.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 10 months ago) by william
File MIME type: text/plain
File size: 5440 byte(s)
committing r3113 initial commit again...
1 /*
2 * pthread_mutexattr_settype.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 "ptw32pch.h"
38
39
40 int
41 pthread_mutexattr_settype (pthread_mutexattr_t * attr, int kind)
42 /*
43 * ------------------------------------------------------
44 *
45 * DOCPUBLIC
46 * The pthread_mutexattr_settype() and
47 * pthread_mutexattr_gettype() functions respectively set and
48 * get the mutex type attribute. This attribute is set in the
49 * type parameter to these functions.
50 *
51 * PARAMETERS
52 * attr
53 * pointer to an instance of pthread_mutexattr_t
54 *
55 * type
56 * must be one of:
57 *
58 * PTHREAD_MUTEX_DEFAULT
59 *
60 * PTHREAD_MUTEX_NORMAL
61 *
62 * PTHREAD_MUTEX_ERRORCHECK
63 *
64 * PTHREAD_MUTEX_RECURSIVE
65 *
66 * DESCRIPTION
67 * The pthread_mutexattr_settype() and
68 * pthread_mutexattr_gettype() functions respectively set and
69 * get the mutex type attribute. This attribute is set in the
70 * type parameter to these functions. The default value of the
71 * type attribute is PTHREAD_MUTEX_DEFAULT.
72 *
73 * The type of mutex is contained in the type attribute of the
74 * mutex attributes. Valid mutex types include:
75 *
76 * PTHREAD_MUTEX_NORMAL
77 * This type of mutex does not detect deadlock. A
78 * thread attempting to relock this mutex without
79 * first unlocking it will deadlock. Attempting to
80 * unlock a mutex locked by a different thread
81 * results in undefined behavior. Attempting to
82 * unlock an unlocked mutex results in undefined
83 * behavior.
84 *
85 * PTHREAD_MUTEX_ERRORCHECK
86 * This type of mutex provides error checking. A
87 * thread attempting to relock this mutex without
88 * first unlocking it will return with an error. A
89 * thread attempting to unlock a mutex which another
90 * thread has locked will return with an error. A
91 * thread attempting to unlock an unlocked mutex will
92 * return with an error.
93 *
94 * PTHREAD_MUTEX_DEFAULT
95 * Same as PTHREAD_MUTEX_NORMAL.
96 *
97 * PTHREAD_MUTEX_RECURSIVE
98 * A thread attempting to relock this mutex without
99 * first unlocking it will succeed in locking the
100 * mutex. The relocking deadlock which can occur with
101 * mutexes of type PTHREAD_MUTEX_NORMAL cannot occur
102 * with this type of mutex. Multiple locks of this
103 * mutex require the same number of unlocks to
104 * release the mutex before another thread can
105 * acquire the mutex. A thread attempting to unlock a
106 * mutex which another thread has locked will return
107 * with an error. A thread attempting to unlock an
108 * unlocked mutex will return with an error. This
109 * type of mutex is only supported for mutexes whose
110 * process shared attribute is
111 * PTHREAD_PROCESS_PRIVATE.
112 *
113 * RESULTS
114 * 0 successfully set attribute,
115 * EINVAL 'attr' or 'type' is invalid,
116 *
117 * ------------------------------------------------------
118 */
119 {
120 int result = 0;
121
122 if ((attr != NULL && *attr != NULL))
123 {
124 switch (kind)
125 {
126 case PTHREAD_MUTEX_FAST_NP:
127 case PTHREAD_MUTEX_RECURSIVE_NP:
128 case PTHREAD_MUTEX_ERRORCHECK_NP:
129 (*attr)->kind = kind;
130 break;
131 default:
132 result = EINVAL;
133 break;
134 }
135 }
136 else
137 {
138 result = EINVAL;
139 }
140
141 return (result);
142 } /* pthread_mutexattr_settype */

  ViewVC Help
Powered by ViewVC 1.1.22