summaryrefslogtreecommitdiffstats
path: root/devel/glib20/files/patch-gthread_gthread-impl.c
blob: 5f1b6dcbd7ec4c1056d9df64b5dbce496e63d4b0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
--- gthread/gthread-impl.c.orig Fri Feb 14 16:08:46 2003
+++ gthread/gthread-impl.c  Wed Jul 20 19:44:08 2005
@@ -37,9 +37,11 @@
 
 #include <glib.h>
 #include <gthreadinit.h>
+#include "gthreadprivate.h"
 
 #ifdef G_THREADS_ENABLED
 
+static GSystemThread zero_thread; /* This is initialized to all zero */
 static gboolean thread_system_already_initialized = FALSE;
 static gint g_thread_priority_map [G_THREAD_PRIORITY_URGENT + 1];
 
@@ -76,7 +78,7 @@
 struct _ErrorCheckInfo
 {
   gchar *location;
-  GThread *owner;
+  GSystemThread owner;
 };
 
 static GMutex *
@@ -94,7 +96,9 @@
                  gchar *location)
 {
   ErrorCheckInfo *info;
-  GThread *self = g_thread_self ();
+  GSystemThread self;
+
+  g_thread_functions_for_glib_use.thread_self (&self);
 
   if (magic != G_MUTEX_DEBUG_MAGIC)
     location = "unknown";
@@ -116,14 +120,14 @@
     }
   
   info = G_MUTEX_DEBUG_INFO (mutex);
-  if (info->owner == self)
+  if (g_system_thread_equal (info->owner, self))
     g_error ("Trying to recursivly lock a mutex at '%s', "
         "previously locked at '%s'", 
         location, info->location);
 
   g_thread_functions_for_glib_use_default.mutex_lock (mutex);
 
-  info->owner = self;
+  g_system_thread_assign (info->owner, self);
   info->location = location;
 }
 
@@ -133,7 +137,9 @@
                 gchar *location)
 {
   ErrorCheckInfo *info = G_MUTEX_DEBUG_INFO (mutex);
-  GThread *self = g_thread_self ();
+  GSystemThread self;
+
+  g_thread_functions_for_glib_use.thread_self (&self);
 
   if (magic != G_MUTEX_DEBUG_MAGIC)
     location = "unknown";
@@ -145,7 +151,7 @@
       return TRUE;
     }
 
-  if (info->owner == self)
+  if (g_system_thread_equal (info->owner, self))
     g_error ("Trying to recursivly lock a mutex at '%s', "
         "previously locked at '%s'", 
         location, info->location);
@@ -153,7 +159,7 @@
   if (!g_thread_functions_for_glib_use_default.mutex_trylock (mutex))
     return FALSE;
 
-  info->owner = self;
+  g_system_thread_assign (info->owner, self);
   info->location = location;
 
   return TRUE;
@@ -165,20 +171,22 @@
                gchar *location)
 {
   ErrorCheckInfo *info = G_MUTEX_DEBUG_INFO (mutex);
-  GThread *self = g_thread_self ();
+  GSystemThread self;
+
+  g_thread_functions_for_glib_use.thread_self (&self);
 
   if (magic != G_MUTEX_DEBUG_MAGIC)
     location = "unknown";
 
-  if (!info || info->owner == NULL)
+  if (!info || g_system_thread_equal (info->owner, zero_thread))
     g_error ("Trying to unlock an unlocked mutex at '%s'", location);
 
-  if (info->owner != self)
+  if (!g_system_thread_equal (info->owner, self))
     g_warning ("Trying to unlock a mutex at '%s', "
           "previously locked by a different thread at '%s'",
           location, info->location);
 
-  info->owner = NULL;
+  g_system_thread_assign (info->owner, zero_thread);
   info->location = NULL;
 
   g_thread_functions_for_glib_use_default.mutex_unlock (mutex);
@@ -194,7 +202,7 @@
   if (magic != G_MUTEX_DEBUG_MAGIC)
     location = "unknown";
 
-  if (info && info->owner != NULL)
+  if (info && !g_system_thread_equal (info->owner, zero_thread))
     g_error ("Trying to free a locked mutex at '%s', "
         "which was previously locked at '%s'", 
         location, info->location);
@@ -211,25 +219,27 @@
 {
   
   ErrorCheckInfo *info = G_MUTEX_DEBUG_INFO (mutex);
-  GThread *self = g_thread_self ();
+  GSystemThread self;
+
+  g_thread_functions_for_glib_use.thread_self (&self);
 
   if (magic != G_MUTEX_DEBUG_MAGIC)
     location = "unknown";
 
-  if (!info || info->owner == NULL)
+  if (!info || g_system_thread_equal (info->owner, zero_thread))
     g_error ("Trying to use an unlocked mutex in g_cond_wait() at '%s'",
         location);
 
-  if (info->owner != self)
+  if (!g_system_thread_equal (info->owner, self))
     g_error ("Trying to use a mutex locked by another thread in "
         "g_cond_wait() at '%s'", location);
 
-  info->owner = NULL;
+  g_system_thread_assign (info->owner, zero_thread);
   location = info->location;
 
   g_thread_functions_for_glib_use_default.cond_wait (cond, mutex);
 
-  info->owner = self;
+  g_system_thread_assign (info->owner, self);
   info->location = location;
 }
     
@@ -242,28 +252,30 @@
                   gchar *location)
 {
   ErrorCheckInfo *info = G_MUTEX_DEBUG_INFO (mutex);
-  GThread *self = g_thread_self ();
+  GSystemThread self;
   gboolean retval;
 
+  g_thread_functions_for_glib_use.thread_self (&self);
+
   if (magic != G_MUTEX_DEBUG_MAGIC)
     location = "unknown";
 
-  if (!info || info->owner == NULL)
+  if (!info || g_system_thread_equal (info->owner, zero_thread))
     g_error ("Trying to use an unlocked mutex in g_cond_timed_wait() at '%s'",
         location);
 
-  if (info->owner != self)
+  if (!g_system_thread_equal (info->owner, self))
     g_error ("Trying to use a mutex locked by another thread in "
         "g_cond_timed_wait() at '%s'", location);
 
-  info->owner = NULL;
+  g_system_thread_assign (info->owner, zero_thread);
   location = info->location;
   
   retval = g_thread_functions_for_glib_use_default.cond_timed_wait (cond, 
                                    mutex, 
                                    end_time);
 
-  info->owner = self;
+  g_system_thread_assign (info->owner, self);
   info->location = location;
 
   return retval;