Mercurial > dwindows
comparison gtk/dw.c @ 1510:218c85939040
Ported fixes in previous commit from GTK2 to GTK3...
Also dw_main_sleep() and dW_main_iteration() needed more complicated locking code on Linux...
Due to Linux's use of fast mutexes double locking will deadlock, and calling dw_main_*()
from a DW API function or callback before starting dw_main() might cause a double lock...
We need to only lock the mutex if it isn't already locked by this thread.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Wed, 28 Dec 2011 14:46:57 +0000 |
parents | 02bfae9fd3e7 |
children | 9d342b67eed5 |
comparison
equal
deleted
inserted
replaced
1509:02bfae9fd3e7 | 1510:218c85939040 |
---|---|
2225 | 2225 |
2226 gettimeofday(&tv, NULL); | 2226 gettimeofday(&tv, NULL); |
2227 | 2227 |
2228 while(((tv.tv_sec - start.tv_sec)*1000) + ((tv.tv_usec - start.tv_usec)/1000) <= milliseconds) | 2228 while(((tv.tv_sec - start.tv_sec)*1000) + ((tv.tv_usec - start.tv_usec)/1000) <= milliseconds) |
2229 { | 2229 { |
2230 int _locked_by_me = FALSE; | |
2231 | |
2230 if(orig == (pthread_t)-1) | 2232 if(orig == (pthread_t)-1) |
2231 { | 2233 { |
2232 gdk_threads_enter(); | 2234 if(!pthread_getspecific(_dw_mutex_key)) |
2235 { | |
2236 gdk_threads_enter(); | |
2237 pthread_setspecific(_dw_mutex_key, (void *)1); | |
2238 _locked_by_me = TRUE; | |
2239 } | |
2233 _dw_thread = curr; | 2240 _dw_thread = curr; |
2234 } | 2241 } |
2235 if(gtk_events_pending()) | 2242 if(curr == _dw_thread && gtk_events_pending()) |
2236 gtk_main_iteration(); | 2243 gtk_main_iteration(); |
2237 else | 2244 else |
2238 _dw_msleep(1); | 2245 _dw_msleep(1); |
2239 if(orig == (pthread_t)-1) | 2246 if(orig == (pthread_t)-1) |
2240 { | 2247 { |
2241 _dw_thread = orig; | 2248 _dw_thread = orig; |
2242 gdk_threads_leave(); | 2249 if(_locked_by_me) |
2250 { | |
2251 pthread_setspecific(_dw_mutex_key, NULL); | |
2252 gdk_threads_leave(); | |
2253 } | |
2243 } | 2254 } |
2244 gettimeofday(&tv, NULL); | 2255 gettimeofday(&tv, NULL); |
2245 } | 2256 } |
2246 } | 2257 } |
2247 else | 2258 else |
2253 */ | 2264 */ |
2254 void dw_main_iteration(void) | 2265 void dw_main_iteration(void) |
2255 { | 2266 { |
2256 pthread_t orig = _dw_thread; | 2267 pthread_t orig = _dw_thread; |
2257 pthread_t curr = pthread_self(); | 2268 pthread_t curr = pthread_self(); |
2269 int _locked_by_me = FALSE; | |
2258 | 2270 |
2259 if(_dw_thread == (pthread_t)-1) | 2271 if(_dw_thread == (pthread_t)-1) |
2260 { | 2272 { |
2273 if(!pthread_getspecific(_dw_mutex_key)) | |
2274 { | |
2275 gdk_threads_enter(); | |
2276 pthread_setspecific(_dw_mutex_key, (void *)1); | |
2277 _locked_by_me = TRUE; | |
2278 } | |
2261 _dw_thread = curr; | 2279 _dw_thread = curr; |
2262 gdk_threads_enter(); | |
2263 } | 2280 } |
2264 if(curr == _dw_thread && gtk_events_pending()) | 2281 if(curr == _dw_thread && gtk_events_pending()) |
2265 gtk_main_iteration(); | 2282 gtk_main_iteration(); |
2266 else | 2283 else |
2267 #ifdef __sun__ | |
2268 sched_yield(); | 2284 sched_yield(); |
2269 #else | |
2270 pthread_yield(); | |
2271 #endif | |
2272 if(orig == (pthread_t)-1) | 2285 if(orig == (pthread_t)-1) |
2273 { | 2286 { |
2274 _dw_thread = (pthread_t)-1; | 2287 _dw_thread = orig; |
2275 gdk_threads_leave(); | 2288 if(_locked_by_me) |
2289 { | |
2290 pthread_setspecific(_dw_mutex_key, NULL); | |
2291 gdk_threads_leave(); | |
2292 } | |
2276 } | 2293 } |
2277 } | 2294 } |
2278 | 2295 |
2279 /* | 2296 /* |
2280 * Free's memory allocated by dynamic windows. | 2297 * Free's memory allocated by dynamic windows. |
10152 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()"); | 10169 _dw_box_pack(box, item, 0, width, height, hsize, vsize, pad, "dw_box_pack_end()"); |
10153 } | 10170 } |
10154 | 10171 |
10155 union extents_union { guchar **gu_extents; unsigned long **extents; }; | 10172 union extents_union { guchar **gu_extents; unsigned long **extents; }; |
10156 static GdkAtom extents_atom = 0; | 10173 static GdkAtom extents_atom = 0; |
10157 static time_t extents_time; | 10174 static time_t extents_time = 0; |
10158 | 10175 |
10159 static gboolean _dw_property_notify(GtkWidget *window, GdkEventProperty* event, GdkWindow *gdkwindow) | 10176 static gboolean _dw_property_notify(GtkWidget *window, GdkEventProperty* event, GdkWindow *gdkwindow) |
10160 { | 10177 { |
10161 /* Check to see if we got a property change */ | 10178 /* Check to see if we got a property change */ |
10162 if(event->state == GDK_PROPERTY_NEW_VALUE && event->atom == extents_atom && event->window == gdkwindow) | 10179 if(event->state == GDK_PROPERTY_NEW_VALUE && event->atom == extents_atom && event->window == gdkwindow) |