Go to the documentation of this file.
25 static char *
t =
"TRUE";
26 static char *
f =
"FALSE";
45 SDL_Log(
"\nspin lock---------------------------------------\n\n");
52 SDL_Log(
"\natomic -----------------------------------------\n\n");
99 #define VALBITS (sizeof(atomicValue)*8)
101 #define atomicValue int
102 #define CountTo ((atomicValue)((unsigned int)(1<<(VALBITS-1))-1))
103 #define NInter (CountTo/CountInc/NThreads)
104 #define Expect (CountTo-NInter*CountInc*NThreads)
107 CountTo_GreaterThanZero =
CountTo > 0,
164 SDL_Log(
"\nepic test---------------------------------------\n\n");
166 SDL_Log(
"Size asserted to be >= 32-bit\n");
169 SDL_Log(
"Check static initializer\n");
175 SDL_Log(
"Test negative values\n");
180 SDL_Log(
"Verify maximum value\n");
185 SDL_Log(
"Test compare and exchange\n");
209 SDL_Log(
"Test Add (Negative values)\n");
226 SDL_Log(
"Reset before count down test\n");
252 #define TEST_SPINLOCK_FIFO
254 #define NUM_READERS 4
255 #define NUM_WRITERS 4
256 #define EVENTS_PER_WRITER 1000000
259 #define MAX_ENTRIES 256
260 #define WRAP_MASK (MAX_ENTRIES-1)
282 #ifdef TEST_SPINLOCK_FIFO
306 #ifdef TEST_SPINLOCK_FIFO
322 #ifdef TEST_SPINLOCK_FIFO
335 delta = (int)(entry_seq - queue_pos);
345 }
else if (delta < 0) {
355 #ifdef TEST_SPINLOCK_FIFO
369 #ifdef TEST_SPINLOCK_FIFO
382 delta = (int)(entry_seq - (queue_pos + 1));
387 *
event = entry->
event;
392 }
else if (delta < 0) {
402 #ifdef TEST_SPINLOCK_FIFO
422 delta = (int)(entry_seq - queue_pos);
430 }
else if (delta < 0) {
433 SDL_Log(
"ERROR: mutex failed!\n");
455 delta = (int)(entry_seq - (queue_pos + 1));
460 *
event = entry->
event;
463 }
else if (delta < 0) {
466 SDL_Log(
"ERROR: mutex failed!\n");
506 event.user.windowID = 0;
508 event.user.data1 =
data;
509 event.user.data2 =
NULL;
511 if (
data->lock_free) {
539 if (
data->lock_free) {
571 #ifdef TEST_SPINLOCK_FIFO
602 char textBuffer[1024];
605 SDL_Log(
"\nFIFO test---------------------------------------\n\n");
606 SDL_Log(
"Mode: %s\n", lock_free ?
"LockFree" :
"Mutex");
620 #ifdef TEST_SPINLOCK_FIFO
634 readerData[
i].
queue = &queue;
646 writerData[
i].
queue = &queue;
690 grand_total += total;
691 SDL_Log(
"Reader %d read %d events, had %d waits\n",
i, total, readerData[
i].waits);
705 SDL_Log(
"Readers read %d total events\n", grand_total);
#define SDL_CACHELINE_SIZE
int main(int argc, char *argv[])
static void RunBasicTest()
static void RunFIFOTest(SDL_bool lock_free)
static int adder(void *junk)
#define SDL_CreateSemaphore
GLboolean GLboolean GLboolean b
SDL_COMPILE_TIME_ASSERT(size, CountTo_GreaterThanZero)
#define EVENTS_PER_WRITER
static SDL_atomic_t readersRunning
#define SDL_AtomicIncRef(a)
Increment an atomic variable used as a reference count.
SDL_EventQueueEntry entries[MAX_ENTRIES]
static SDL_atomic_t writersRunning
static SDL_sem * threadDone
static int FIFO_Watcher(void *_data)
static SDL_sem * writersDone
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLint GLint GLsizei GLuint * counters
static void InitEventQueue(SDL_EventQueue *queue)
#define SDL_AtomicDecRef(a)
Decrement an atomic variable used as a reference count.
static SDL_atomic_t threadsRunning
GLuint const GLchar * name
static void RunEpicTest()
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
int counters[NUM_WRITERS]
static char * tf(SDL_bool tf)
static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event)
#define SDL_assert(condition)
static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *event)
static int FIFO_Reader(void *_data)
static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
static SDL_sem * readersDone
#define SDL_LogSetPriority
GLsizei const GLfloat * value
static int FIFO_Writer(void *_data)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int int in j)
A type representing an atomic integer value. It is a struct so people don't accidentally use numeric ...
static void runAdder(void)
#define SDL_DestroySemaphore
static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)