mesa/glthread: remove HAVE_PTHREAD guards
[mesa.git] / src / mesa / main / glthread.h
1 /*
2 * Copyright © 2012 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #ifndef _GLTHREAD_H
25 #define _GLTHREAD_H
26
27 #include "main/mtypes.h"
28
29 /* Command size is a number of bytes stored in a short. */
30 #define MARSHAL_MAX_CMD_SIZE 65535
31
32 #include <inttypes.h>
33 #include <stdbool.h>
34 #include <pthread.h>
35
36 enum marshal_dispatch_cmd_id;
37
38 struct glthread_state
39 {
40 /** The worker thread that asynchronously processes our GL commands. */
41 pthread_t thread;
42
43 /**
44 * Mutex used for synchronizing between the main thread and the worker
45 * thread.
46 */
47 pthread_mutex_t mutex;
48
49 /** Condvar used for waking the worker thread. */
50 pthread_cond_t new_work;
51
52 /** Condvar used for waking the main thread. */
53 pthread_cond_t work_done;
54
55 /** Used to tell the worker thread to quit */
56 bool shutdown;
57
58 /** Indicates that the worker thread is currently processing a batch */
59 bool busy;
60
61 /**
62 * Singly-linked list of command batches that are awaiting execution by
63 * a thread pool task. NULL if empty.
64 */
65 struct glthread_batch *batch_queue;
66
67 /**
68 * Tail pointer for appending batches to the end of batch_queue. If the
69 * queue is empty, this points to batch_queue.
70 */
71 struct glthread_batch **batch_queue_tail;
72
73 /**
74 * Batch containing commands that are being prepared for insertion into
75 * batch_queue. NULL if there are no such commands.
76 *
77 * Since this is only used by the main thread, it doesn't need the mutex to
78 * be accessed.
79 */
80 struct glthread_batch *batch;
81
82 /**
83 * Tracks on the main thread side whether the current vertex array binding
84 * is in a VBO.
85 */
86 bool vertex_array_is_vbo;
87
88 /**
89 * Tracks on the main thread side whether the current element array (index
90 * buffer) binding is in a VBO.
91 */
92 bool element_array_is_vbo;
93 };
94
95 /**
96 * A single batch of commands queued up for later execution by a thread pool
97 * task.
98 */
99 struct glthread_batch
100 {
101 /**
102 * Next batch of commands to execute after this batch, or NULL if this is
103 * the last set of commands queued. Protected by ctx->Marshal.Mutex.
104 */
105 struct glthread_batch *next;
106
107 /**
108 * Amount of data used by batch commands, in bytes.
109 */
110 size_t used;
111
112 /**
113 * Data contained in the command buffer.
114 */
115 uint8_t buffer[MARSHAL_MAX_CMD_SIZE];
116 };
117
118 void _mesa_glthread_init(struct gl_context *ctx);
119 void _mesa_glthread_destroy(struct gl_context *ctx);
120
121 void _mesa_glthread_restore_dispatch(struct gl_context *ctx);
122 void _mesa_glthread_flush_batch(struct gl_context *ctx);
123 void _mesa_glthread_finish(struct gl_context *ctx);
124
125 #endif /* _GLTHREAD_H*/