nvfx: expose GLSL
[mesa/mesa-lb.git] / src / gallium / drivers / llvmpipe / lp_fence.c
blob525c117f316592690bc89f515641ac34ab21852a
1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "pipe/p_screen.h"
30 #include "util/u_memory.h"
31 #include "util/u_inlines.h"
32 #include "lp_fence.h"
35 struct lp_fence *
36 lp_fence_create(unsigned rank)
38 struct lp_fence *fence = CALLOC_STRUCT(lp_fence);
40 pipe_reference_init(&fence->reference, 1);
42 pipe_mutex_init(fence->mutex);
43 pipe_condvar_init(fence->signalled);
45 fence->rank = rank;
47 return fence;
51 static void
52 lp_fence_destroy(struct lp_fence *fence)
54 pipe_mutex_destroy(fence->mutex);
55 pipe_condvar_destroy(fence->signalled);
56 FREE(fence);
60 static void
61 llvmpipe_fence_reference(struct pipe_screen *screen,
62 struct pipe_fence_handle **ptr,
63 struct pipe_fence_handle *fence)
65 struct lp_fence *old = (struct lp_fence *) *ptr;
66 struct lp_fence *f = (struct lp_fence *) fence;
68 if (pipe_reference(&old->reference, &f->reference)) {
69 lp_fence_destroy(old);
74 static int
75 llvmpipe_fence_signalled(struct pipe_screen *screen,
76 struct pipe_fence_handle *fence,
77 unsigned flag)
79 struct lp_fence *f = (struct lp_fence *) fence;
81 return f->count == f->rank;
85 static int
86 llvmpipe_fence_finish(struct pipe_screen *screen,
87 struct pipe_fence_handle *fence_handle,
88 unsigned flag)
90 struct lp_fence *fence = (struct lp_fence *) fence_handle;
92 pipe_mutex_lock(fence->mutex);
93 while (fence->count < fence->rank) {
94 pipe_condvar_wait(fence->signalled, fence->mutex);
96 pipe_mutex_unlock(fence->mutex);
98 return 0;
104 void
105 llvmpipe_init_screen_fence_funcs(struct pipe_screen *screen)
107 screen->fence_reference = llvmpipe_fence_reference;
108 screen->fence_signalled = llvmpipe_fence_signalled;
109 screen->fence_finish = llvmpipe_fence_finish;