desc.Height = pParams->BackBufferHeight;
if (This->pool) {
- _mesa_threadpool_destroy(This->pool);
+ _mesa_threadpool_destroy(This, This->pool);
This->pool = NULL;
}
This->enable_threadpool = This->actx->thread_submit && (pParams->SwapEffect != D3DSWAPEFFECT_COPY);
if (This->enable_threadpool)
- This->pool = _mesa_threadpool_create();
+ This->pool = _mesa_threadpool_create(This);
if (!This->pool)
This->enable_threadpool = FALSE;
DBG("This=%p\n", This);
if (This->pool)
- _mesa_threadpool_destroy(This->pool);
+ _mesa_threadpool_destroy(This, This->pool);
if (This->buffers) {
for (i = 0; i < This->params.BackBufferCount; i++) {
return FALSE;
}
+
+HANDLE
+NineSwapChain9_CreateThread( struct NineSwapChain9 *This,
+ void *pFuncAddress,
+ void *pParam )
+{
+ if (This->base.device->minor_version_num > 1) {
+ return ID3DPresent_CreateThread(This->present, pFuncAddress, pParam);
+ }
+
+ return NULL;
+}
+
+void
+NineSwapChain9_WaitForThread( struct NineSwapChain9 *This,
+ HANDLE thread )
+{
+ if (This->base.device->minor_version_num > 1) {
+ (void) ID3DPresent_WaitForThread(This->present, thread);
+ }
+}
BOOL
NineSwapChain9_ResolutionMismatch( struct NineSwapChain9 *This );
+HANDLE
+NineSwapChain9_CreateThread( struct NineSwapChain9 *This,
+ void *pFuncAddress,
+ void *pParam );
+
+void
+NineSwapChain9_WaitForThread( struct NineSwapChain9 *This,
+ HANDLE thread );
+
#endif /* _NINE_SWAPCHAIN9_H_ */
}
struct threadpool *
-_mesa_threadpool_create(void)
+_mesa_threadpool_create(struct NineSwapChain9 *swapchain)
{
struct threadpool *pool = calloc(1, sizeof(*pool));
pthread_mutex_init(&pool->m, NULL);
pthread_cond_init(&pool->new_work, NULL);
- pthread_create(&pool->thread, NULL, threadpool_worker, pool);
-
+ pool->wthread = NineSwapChain9_CreateThread(swapchain, threadpool_worker, pool);
+ if (!pool->wthread) {
+ /* using pthread as fallback */
+ pthread_create(&pool->pthread, NULL, threadpool_worker, pool);
+ }
return pool;
}
void
-_mesa_threadpool_destroy(struct threadpool *pool)
+_mesa_threadpool_destroy(struct NineSwapChain9 *swapchain, struct threadpool *pool)
{
if (!pool)
return;
pthread_cond_broadcast(&pool->new_work);
pthread_mutex_unlock(&pool->m);
- pthread_join(pool->thread, NULL);
+ if (pool->wthread) {
+ NineSwapChain9_WaitForThread(swapchain, pool->wthread);
+ } else {
+ pthread_join(pool->pthread, NULL);
+ }
pthread_cond_destroy(&pool->new_work);
pthread_mutex_destroy(&pool->m);
#ifndef _THREADPOOL_H_
#define _THREADPOOL_H_
+struct NineSwapChain9;
+
#define MAXTHREADS 1
struct threadpool {
pthread_mutex_t m;
pthread_cond_t new_work;
- pthread_t thread;
+ HANDLE wthread;
+ pthread_t pthread;
struct threadpool_task *workqueue;
BOOL shutdown;
};
BOOL finished;
};
-struct threadpool *_mesa_threadpool_create(void);
-void _mesa_threadpool_destroy(struct threadpool *pool);
+struct threadpool *_mesa_threadpool_create(struct NineSwapChain9 *swapchain);
+void _mesa_threadpool_destroy(struct NineSwapChain9 *swapchain, struct threadpool *pool);
struct threadpool_task *_mesa_threadpool_queue_task(struct threadpool *pool,
threadpool_task_func func,
void *data);
void _mesa_threadpool_wait_for_task(struct threadpool *pool,
struct threadpool_task **task);
-#endif
\ No newline at end of file
+#endif