17 #include <SDL_thread.h>
53 SDL_mutex *data_mutex;
65 full_slots = SDL_CreateSemaphore(0);
66 free_slots = SDL_CreateSemaphore(n);
67 data_mutex = SDL_CreateMutex();
74 SDL_DestroyMutex (data_mutex);
75 SDL_DestroySemaphore(free_slots);
76 SDL_DestroySemaphore(full_slots);
85 if (SDL_SemTryWait(free_slots) == 0)
87 SDL_LockMutex(data_mutex);
91 SDL_UnlockMutex(data_mutex);
92 SDL_SemPost(full_slots);
102 if (SDL_SemTryWait(full_slots) == 0)
104 SDL_LockMutex(data_mutex);
109 SDL_UnlockMutex(data_mutex);
110 SDL_SemPost(free_slots);
122 SDL_SemWait(free_slots);
123 SDL_LockMutex(data_mutex);
127 SDL_UnlockMutex(data_mutex);
128 SDL_SemPost(full_slots);
137 SDL_SemWait(full_slots);
138 SDL_LockMutex(data_mutex);
143 SDL_UnlockMutex(data_mutex);
144 SDL_SemPost(free_slots);
T remove()
Blocking dequeue for use by the loader threads.
Definition: scm-queue.hpp:133
bool try_remove(T &)
Non-blocking dequeue for use by the render thread.
Definition: scm-queue.hpp:100
An scm_queue implements a templated producer-consumer priority queue.
Definition: scm-queue.hpp:36
void insert(T)
Blocking enqueue for use by the loader threads.
Definition: scm-queue.hpp:120
scm_queue(int n)
Create a new queue with n slots. Initialize counting semaphores for full slots and empty slots...
Definition: scm-queue.hpp:63
bool try_insert(T &)
Non-blocking enqueue for use by the render thread.
Definition: scm-queue.hpp:83
~scm_queue()
Finalize a queue and release its mutex and semaphores.
Definition: scm-queue.hpp:72