Home | History | Annotate | Download | only in test

Lines Matching defs:queue

249 /* This is useful to test the impact of another thread locking the queue
297 static void InitEventQueue(SDL_EventQueue *queue)
302 SDL_AtomicSet(&queue->entries[i].sequence, i);
304 SDL_AtomicSet(&queue->enqueue_pos, 0);
305 SDL_AtomicSet(&queue->dequeue_pos, 0);
307 queue->lock = 0;
308 SDL_AtomicSet(&queue->rwcount, 0);
310 queue->active = SDL_TRUE;
313 static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *event)
322 /* This is a gate so an external thread can lock the queue */
323 SDL_AtomicLock(&queue->lock);
324 SDL_assert(SDL_AtomicGet(&queue->watcher) == 0);
325 SDL_AtomicIncRef(&queue->rwcount);
326 SDL_AtomicUnlock(&queue->lock);
329 queue_pos = (unsigned)SDL_AtomicGet(&queue->enqueue_pos);
331 entry = &queue->entries[queue_pos & WRAP_MASK];
336 /* The entry and the queue position match, try to increment the queue position */
337 if (SDL_AtomicCAS(&queue->enqueue_pos, (int)queue_pos, (int)(queue_pos+1))) {
345 /* We ran into an old queue entry, which means it still needs to be dequeued */
349 /* We ran into a new queue entry, get the new queue position */
350 queue_pos = (unsigned)SDL_AtomicGet(&queue->enqueue_pos);
355 SDL_AtomicDecRef(&queue->rwcount);
360 static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event)
369 /* This is a gate so an external thread can lock the queue */
370 SDL_AtomicLock(&queue->lock);
371 SDL_assert(SDL_AtomicGet(&queue->watcher) == 0);
372 SDL_AtomicIncRef(&queue->rwcount);
373 SDL_AtomicUnlock(&queue->lock);
376 queue_pos = (unsigned)SDL_AtomicGet(&queue->dequeue_pos);
378 entry = &queue->entries[queue_pos & WRAP_MASK];
383 /* The entry and the queue position match, try to increment the queue position */
384 if (SDL_AtomicCAS(&queue->dequeue_pos, (int)queue_pos, (int)(queue_pos+1))) {
392 /* We ran into an old queue entry, which means we've hit empty */
396 /* We ran into a new queue entry, get the new queue position */
397 queue_pos = (unsigned)SDL_AtomicGet(&queue->dequeue_pos);
402 SDL_AtomicDecRef(&queue->rwcount);
407 static SDL_bool EnqueueEvent_Mutex(SDL_EventQueue *queue, const SDL_Event *event)
415 SDL_LockMutex(queue->mutex);
417 queue_pos = (unsigned)queue->enqueue_pos.value;
418 entry = &queue->entries[queue_pos & WRAP_MASK];
423 ++queue->enqueue_pos.value;
430 /* We ran into an old queue entry, which means it still needs to be dequeued */
435 SDL_UnlockMutex(queue->mutex);
440 static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
448 SDL_LockMutex(queue->mutex);
450 queue_pos = (unsigned)queue->dequeue_pos.value;
451 entry = &queue->entries[queue_pos & WRAP_MASK];
456 ++queue->dequeue_pos.value;
463 /* We ran into an old queue entry, which means we've hit empty */
468 SDL_UnlockMutex(queue->mutex);
480 SDL_EventQueue *queue;
490 SDL_EventQueue *queue;
500 SDL_EventQueue *queue = data->queue;
513 while (!EnqueueEvent_LockFree(queue, &event)) {
521 while (!EnqueueEvent_Mutex(queue, &event)) {
535 SDL_EventQueue *queue = data->queue;
540 if (DequeueEvent_LockFree(queue, &event)) {
543 } else if (queue->active) {
547 /* We drained the queue, we're done! */
553 if (DequeueEvent_Mutex(queue, &event)) {
556 } else if (queue->active) {
560 /* We drained the queue, we're done! */
571 /* This thread periodically locks the queue for no particular reason */
574 SDL_EventQueue *queue = (SDL_EventQueue *)_data;
576 while (queue->active) {
577 SDL_AtomicLock(&queue->lock);
578 SDL_AtomicIncRef(&queue->watcher);
579 while (SDL_AtomicGet(&queue->rwcount) > 0) {
582 /* Do queue manipulation here... */
583 SDL_AtomicDecRef(&queue->watcher);
584 queue->lock);
595 SDL_EventQueue queue;
610 SDL_memset(&queue, 0xff, sizeof(queue));
612 InitEventQueue(&queue);
614 queue.mutex = SDL_CreateMutex();
622 SDL_CreateThread(FIFO_Watcher, "FIFOWatcher", &queue);
633 readerData[i].queue = &queue;
645 writerData[i].queue = &queue;
656 /* Shut down the queue so readers exit */
657 queue.active = SDL_FALSE;
670 SDL_DestroyMutex(queue.mutex);