archrelease: copy trunk to community-any
[ArchLinux/community.git] / lib32-primus / trunk / register_cleanup.patch
blob6f58e87c977a1822a11fb9cfca93f2adcbbd00f0
1 diff --git a/libglfork.cpp b/libglfork.cpp
2 index 03f514f..bb42f0d 100644
3 --- a/libglfork.cpp
4 +++ b/libglfork.cpp
5 @@ -259,6 +259,22 @@ static struct PrimusInfo {
7 } primus;
9 +static void cleanup()
11 + primus.drawables.clear();
14 +static void register_cleanup_1()
16 + atexit(cleanup);
19 +static void register_cleanup()
21 + static pthread_once_t once = PTHREAD_ONCE_INIT;
22 + pthread_once(&once, register_cleanup_1);
25 // Thread-specific data
26 static __thread struct {
27 Display *dpy;
28 @@ -622,11 +638,6 @@ GLXContext glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config, GLXConte
29 void glXDestroyContext(Display *dpy, GLXContext ctx)
31 primus.contexts.erase(ctx);
32 - // kludge: reap background tasks when deleting the last context
33 - // otherwise something will deadlock during unloading the library
34 - if (primus.contexts.empty())
35 - for (DrawablesInfo::iterator i = primus.drawables.begin(); i != primus.drawables.end(); i++)
36 - i->second.reap_workers();
37 primus.afns.glXDestroyContext(primus.adpy, ctx);
40 @@ -720,6 +731,7 @@ void glXSwapBuffers(Display *dpy, GLXDrawable drawable)
41 di.actx = ctx;
42 di.d.spawn_worker(drawable, display_work);
43 di.r.spawn_worker(drawable, readback_work);
44 + register_cleanup();
46 // Readback thread needs a sync object to avoid reading an incomplete frame
47 di.sync = primus.afns.glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);