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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations) (download)
Tue Sep 7 03:24:11 2010 UTC (9 years, 11 months ago) by william
File MIME type: text/plain
File size: 3105 byte(s)
committing r3113 initial commit again...
1 /*
2 * pthread_spin_init.c
3 *
4 * Description:
5 * This translation unit implements spin lock 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_spin_init (pthread_spinlock_t * lock, int pshared)
42 {
43 pthread_spinlock_t s;
44 int cpus = 0;
45 int result = 0;
46
47 if (lock == NULL)
48 {
49 return EINVAL;
50 }
51
52 #ifdef PTW32_STATIC_LIB
53 // This allos for C++ static initializers to function without crashes. (air)
54 pthread_win32_process_attach_np();
55 #endif
56
57 // Optimized this so that it doesn't do cpu count checks needlessly. (air)
58 #if _POSIX_THREAD_PROCESS_SHARED >= 0
59 /*
60 * Not implemented yet.
61 */
62
63 if (0 != ptw32_getprocessors (&cpus))
64 {
65 cpus = 1;
66 }
67
68 if (cpus > 1)
69 {
70 if (pshared == PTHREAD_PROCESS_SHARED)
71 {
72 /*
73 * Creating spinlock that can be shared between
74 * processes.
75 */
76
77 #error ERROR [__FILE__, line __LINE__]: Process shared spin locks are not supported yet.
78
79
80 }
81 }
82
83 #else
84
85 if (pshared == PTHREAD_PROCESS_SHARED)
86 return ENOSYS;
87
88 #endif /* _POSIX_THREAD_PROCESS_SHARED */
89
90 s = (pthread_spinlock_t) calloc (1, sizeof (*s));
91
92 if (s == NULL)
93 {
94 return ENOMEM;
95 }
96
97 if (cpus > 1)
98 {
99 s->u.cpus = cpus;
100 s->interlock = PTW32_SPIN_UNLOCKED;
101 }
102 else
103 {
104 pthread_mutexattr_t ma;
105 result = pthread_mutexattr_init (&ma);
106
107 if (0 == result)
108 {
109 ma->pshared = pshared;
110 result = pthread_mutex_init (&(s->u.mutex), &ma);
111 if (0 == result)
112 {
113 s->interlock = PTW32_SPIN_USE_MUTEX;
114 }
115 }
116 (void) pthread_mutexattr_destroy (&ma);
117 }
118
119 if (0 == result)
120 {
121 *lock = s;
122 }
123 else
124 {
125 (void) free (s);
126 *lock = NULL;
127 }
128
129 return (result);
130 }

  ViewVC Help
Powered by ViewVC 1.1.22