Add TLS support to libGL and, by virtue of using glthread.h and GL_CALL, all
DRI drivers.  A TLS enabled libGL can load a TLS or a non-TLS DRI driver,
but a TLS DRI driver requires a TLS enabled libGL.

This fixes bug #1822.
diff --git a/src/mesa/glapi/glthread.h b/src/mesa/glapi/glthread.h
index 1d2a4a7..615d169 100644
--- a/src/mesa/glapi/glthread.h
+++ b/src/mesa/glapi/glthread.h
@@ -306,7 +306,14 @@
 extern void
 _glthread_SetTSD(_glthread_TSD *, void *);
 
-#ifndef GL_CALL
+#if defined(GLX_USE_TLS)
+
+extern __thread struct _glapi_table * _glapi_tls_Dispatch
+    __attribute__((tls_model("initial-exec")));
+
+# define GL_CALL(name) (*(_glapi_tls_Dispatch-> name))
+
+#elif !defined(GL_CALL)
 # if defined(THREADS)
 extern struct _glapi_table * _glapi_DispatchTSD;
 #  define GL_CALL(name) \