mesa: Add a pthread pool implementation.
threadpool: Fix deadlock if task completion races with wait_for_task.

threadpool_worker() doesn't lock the threadpool mutex before setting
task->finished.  As a result, it can race with
_mesa_threadpool_wait_for_task()'s attempt to determine whether the
task has completed, resulting in the following deadlock:

Worker thread:                     Main thread:
/* threadpool_worker() */          /* _mesa_threadpool_wait_for_task() */
pthread_mutex_unlock(&pool->m);
task->work(task->data);
                                   pthread_mutex_lock(&pool->m);
                                   while (!task->finished) /* not finished */
task->finished = GL_TRUE;
pthread_cond_broadcast(
    &task->finish);
                                     pthread_cond_wait(&task->finish,
                                                       &pool->m);
pthread_mutex_lock(&pool->m);
/* Goes on to other tasks */       /* Waits forever */

This patch avoids the race condition by having threadpool_worker()
lock the mutex before modifying task->finished.
Add new marshalling interfaces to dri_interface.h.
Update dri_util to keep track of __DRI_BACKGROUND_CALLABLE
Add SetBackgroundContext to dd_function_table
Hook up dd_function_table::SetBackgroundContext in intel driver.
Implement __DRI_BACKGROUND_CALLABLE in glx.  TODO: also do in egl, etc.
GLX: take note if server exposes __DRI_MULTITHREADED
GLX: synchronize before swap
GLX: Synchronize before CopySubBuffer
Annotate functions with "marshal" attribute in GLAPI XML.

Several API functions require special treatment in order to be
marshalled to a background thread.  Others can't be safely executed in
a background thread and need to be executed synchronously (e.g. since
they return data through a pointer argument).

This annotation will be used when code generating thread marshalling
code, to ensure that each function is marshalled in the correct way.

The possible annotations are:

- "draw": this is a draw call, and hence may access memory through
  pointers that were set up by a previous call to
  e.g. glVertexAttribPointer(), so it needs to be marshalled
  specially.

- "async": this call should be marshalled to a background thread by
  storing all of its arguments in a buffer that is shared with the
  background thread.

- "sync": this call should not be marshalled to a background
  thread--it should be executed synchronously.

- "custom": the marshalling for this function is complex enough that
  it can't be code generated--it will be hand-coded instead.

Note that GL calls that return void will be treated as "async" by
default, and GL calls that return non-void will be treated as "sync"
by default.

Note that PixelMap functions are marked as synchronous for now since
their pointer may be relative to buffer on the GPU, so we'll need
special logic to marshal them properly.
Add python scripts to code generate GL API marshalling code.

These scripts are not yet used.
Set up thread marshalling data structures and thread pool.
Add marshal.c and marshal.h files.
Create pointers for multithread marshalling dispatch table.

This patch splits the context's CurrentDispatch pointer into two
pointers, CurrentClientDispatch, and CurrentServerDispatch, so that
when doing multithread marshalling, we can distinguish between the
dispatch table that's being used by the client (to serialize GL calls
into the marshal buffer) and the dispatch table that's being used by
the server (to execute the GL calls).
Add marshal.c and code generation to build.
Add code to enable multithreading.

Multithreading only occurs if _mesa_enable_multithreading() is
called.
Implement __DRI_MULTITHREADED for Intel
Activate multithreading for i965
Custom thread marshalling for ShaderSource.