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
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_assert(condition)
#define SDL_AtomicDecRef(a)
Decrement an atomic variable used as a reference count.
#define SDL_AtomicIncRef(a)
Increment an atomic variable used as a reference count.
#define SDL_CACHELINE_SIZE
#define SDL_DestroySemaphore
#define SDL_LogSetPriority
#define SDL_CreateSemaphore
@ SDL_LOG_CATEGORY_APPLICATION
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLboolean GLboolean GLboolean b
GLuint const GLchar * name
GLint GLint GLsizei GLuint * counters
GLsizei const GLfloat * value
Uint32 SDL_GetTicks(void)
Get the number of milliseconds since the SDL library initialization.
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)
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)
int counters[NUM_WRITERS]
SDL_EventQueueEntry entries[MAX_ENTRIES]
A type representing an atomic integer value. It is a struct so people don't accidentally use numeric ...
static SDL_atomic_t writersRunning
int main(int argc, char *argv[])
static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
static int FIFO_Watcher(void *_data)
static void RunFIFOTest(SDL_bool lock_free)
SDL_COMPILE_TIME_ASSERT(size, CountTo_GreaterThanZero)
static SDL_sem * threadDone
static SDL_atomic_t readersRunning
static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event)
static int FIFO_Reader(void *_data)
static int FIFO_Writer(void *_data)
static SDL_sem * readersDone
static char * tf(SDL_bool tf)
static SDL_sem * writersDone
#define EVENTS_PER_WRITER
static void RunEpicTest()
static void InitEventQueue(SDL_EventQueue *queue)
static void RunBasicTest()
static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *event)
static int adder(void *junk)
static void runAdder(void)
static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event)
static SDL_atomic_t threadsRunning