summaryrefslogtreecommitdiff
path: root/drivers/mxc/gpu-viv/hal/kernel/gc_hal_kernel_interrupt_vg.c
blob: cbc921a713b0a00b4e6ba72fa4dc9cbf6cb5aae3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
/****************************************************************************
*
*    Copyright (C) 2005 - 2011 by Vivante Corp.
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the license, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program; if not write to the Free Software
*    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*****************************************************************************/




#include "gc_hal_kernel_precomp.h"

#if gcdENABLE_VG

/******************************************************************************\
*********************** Support Functions and Definitions **********************
\******************************************************************************/

/* Interruot statistics will be accumulated if not zero. */
#define gcmENABLE_INTERRUPT_STATISTICS 0

#define _GC_OBJ_ZONE    gcvZONE_INTERRUPT

/* Object structure. */
struct _gckVGINTERRUPT
{
    /* Object. */
    gcsOBJECT                   object;

    /* gckVGKERNEL pointer. */
    gckVGKERNEL                 kernel;

    /* gckOS pointer. */
    gckOS                       os;

    /* Interrupt handlers. */
    gctINTERRUPT_HANDLER        handlers[32];

    /* Main interrupt handler thread. */
    gctTHREAD                   handler;
    gctBOOL                     terminate;

    /* Interrupt FIFO. */
    gctSEMAPHORE                fifoValid;
    gctUINT32                   fifo[256];
    gctUINT                     fifoItems;
    gctUINT8                    head;
    gctUINT8                    tail;

    /* Interrupt statistics. */
#if gcmENABLE_INTERRUPT_STATISTICS
    gctUINT                     maxFifoItems;
    gctUINT                     fifoOverflow;
    gctUINT                     maxSimultaneous;
    gctUINT                     multipleCount;
#endif
};


/*******************************************************************************
**
**  _ProcessInterrupt
**
**  The interrupt processor.
**
**  INPUT:
**
**      ThreadParameter
**          Pointer to the gckVGINTERRUPT object.
**
**  OUTPUT:
**
**      Nothing.
*/

#if gcmENABLE_INTERRUPT_STATISTICS
static void
_ProcessInterrupt(
    gckVGINTERRUPT Interrupt,
    gctUINT_PTR TriggeredCount
    )
#else
static void
_ProcessInterrupt(
    gckVGINTERRUPT Interrupt
    )
#endif
{
    gceSTATUS status;
    gctUINT32 triggered;
    gctUINT i;

    /* Advance to the next entry. */
    Interrupt->tail      += 1;
    Interrupt->fifoItems -= 1;

    /* Get the interrupt value. */
    triggered = Interrupt->fifo[Interrupt->tail];
    gcmkASSERT(triggered != 0);

    gcmkTRACE_ZONE(
        gcvLEVEL_VERBOSE, gcvZONE_COMMAND,
        "%s: triggered=0x%08X\n",
        __FUNCTION__,
        triggered
        );

    /* Walk through all possible interrupts. */
    for (i = 0; i < gcmSIZEOF(Interrupt->handlers); i += 1)
    {
        /* Test if interrupt happened. */
        if ((triggered & 1) == 1)
        {
#if gcmENABLE_INTERRUPT_STATISTICS
            if (TriggeredCount != gcvNULL)
            {
                (* TriggeredCount) += 1;
            }
#endif

            /* Make sure we have valid handler. */
            if (Interrupt->handlers[i] == gcvNULL)
            {
                gcmkTRACE(
                    gcvLEVEL_ERROR,
                    "%s: Interrupt %d isn't registered.\n",
                    __FUNCTION__, i
                    );
            }
            else
            {
                gcmkTRACE_ZONE(
                    gcvLEVEL_VERBOSE, gcvZONE_COMMAND,
                    "%s: interrupt=%d\n",
                    __FUNCTION__,
                    i
                    );

                /* Call the handler. */
                status = Interrupt->handlers[i] (Interrupt->kernel);

                if (gcmkIS_ERROR(status))
                {
                    /* Failed to signal the semaphore. */
                    gcmkTRACE(
                        gcvLEVEL_ERROR,
                        "%s: Error %d incrementing the semaphore #%d.\n",
                        __FUNCTION__, status, i
                        );
                }
            }
        }

        /* Next interrupt. */
        triggered >>= 1;

        /* No more interrupts to handle? */
        if (triggered == 0)
        {
            break;
        }
    }
}


/*******************************************************************************
**
**  _MainInterruptHandler
**
**  The main interrupt thread serves the interrupt FIFO and calls registered
**  handlers for the interrupts that occured. The handlers are called in the
**  sequence interrupts occured with the exception when multiple interrupts
**  occured at the same time. In that case the handler calls are "sorted" by
**  the interrupt number therefore giving the interrupts with lower numbers
**  higher priority.
**
**  INPUT:
**
**      ThreadParameter
**          Pointer to the gckVGINTERRUPT object.
**
**  OUTPUT:
**
**      Nothing.
*/

static gctTHREADFUNCRESULT gctTHREADFUNCTYPE
_MainInterruptHandler(
    gctTHREADFUNCPARAMETER ThreadParameter
    )
{
    gceSTATUS status;
    gckVGINTERRUPT interrupt;

#if gcmENABLE_INTERRUPT_STATISTICS
    gctUINT count;
#endif

    /* Cast the object. */
    interrupt = (gckVGINTERRUPT) ThreadParameter;

    /* Enter the loop. */
    while (gcvTRUE)
    {
        /* Wait for an interrupt. */
        status = gckOS_DecrementSemaphore(interrupt->os, interrupt->fifoValid);

        /* Error? */
        if (gcmkIS_ERROR(status))
        {
            break;
        }

        /* System termination request? */
        if (status == gcvSTATUS_TERMINATE)
        {
            break;
        }

        /* Driver is shutting down? */
        if (interrupt->terminate)
        {
            break;
        }

#if gcmENABLE_INTERRUPT_STATISTICS
        /* Reset triggered count. */
        count = 0;

        /* Process the interrupt. */
        _ProcessInterrupt(interrupt, &count);

        /* Update conters. */
        if (count > interrupt->maxSimultaneous)
        {
            interrupt->maxSimultaneous = count;
        }

        if (count > 1)
        {
            interrupt->multipleCount += 1;
        }
#else
        /* Process the interrupt. */
        _ProcessInterrupt(interrupt);
#endif
    }

    return 0;
}


/*******************************************************************************
**
**  _StartInterruptHandler / _StopInterruptHandler
**
**  Main interrupt handler routine control.
**
**  INPUT:
**
**      ThreadParameter
**          Pointer to the gckVGINTERRUPT object.
**
**  OUTPUT:
**
**      Nothing.
*/

static gceSTATUS
_StartInterruptHandler(
    gckVGINTERRUPT Interrupt
    )
{
    gceSTATUS status, last;

    do
    {
        /* Objects must not be already created. */
        gcmkASSERT(Interrupt->fifoValid == gcvNULL);
        gcmkASSERT(Interrupt->handler   == gcvNULL);

        /* Reset the termination request. */
        Interrupt->terminate = gcvFALSE;

#if !gcdENABLE_INFINITE_SPEED_HW
        /* Construct the fifo semaphore. */
        gcmkERR_BREAK(gckOS_CreateSemaphoreVG(
            Interrupt->os, &Interrupt->fifoValid
            ));

        /* Start the interrupt handler thread. */
        gcmkERR_BREAK(gckOS_StartThread(
            Interrupt->os,
            _MainInterruptHandler,
            Interrupt,
            &Interrupt->handler
            ));
#endif

        /* Success. */
        return gcvSTATUS_OK;
    }
    while (gcvFALSE);

    /* Roll back. */
    if (Interrupt->fifoValid != gcvNULL)
    {
        gcmkCHECK_STATUS(gckOS_DestroySemaphore(
            Interrupt->os, Interrupt->fifoValid
            ));

        Interrupt->fifoValid = gcvNULL;
    }

    /* Return the status. */
    return status;
}

static gceSTATUS
_StopInterruptHandler(
    gckVGINTERRUPT Interrupt
    )
{
    gceSTATUS status;

    do
    {
        /* Does the thread exist? */
        if (Interrupt->handler == gcvNULL)
        {
            /* The semaphore must be NULL as well. */
            gcmkASSERT(Interrupt->fifoValid == gcvNULL);

            /* Success. */
            status = gcvSTATUS_OK;
            break;
        }

        /* The semaphore must exist as well. */
        gcmkASSERT(Interrupt->fifoValid != gcvNULL);

        /* Set the termination request. */
        Interrupt->terminate = gcvTRUE;

        /* Unlock the thread. */
        gcmkERR_BREAK(gckOS_IncrementSemaphore(
            Interrupt->os, Interrupt->fifoValid
            ));

        /* Wait until the thread quits. */
        gcmkERR_BREAK(gckOS_StopThread(
            Interrupt->os,
            Interrupt->handler
            ));

        /* Destroy the semaphore. */
        gcmkERR_BREAK(gckOS_DestroySemaphore(
            Interrupt->os, Interrupt->fifoValid
            ));

        /* Reset handles. */
        Interrupt->handler   = gcvNULL;
        Interrupt->fifoValid = gcvNULL;
    }
    while (gcvFALSE);

    /* Return the status. */
    return status;
}


/******************************************************************************\
***************************** Interrupt Object API *****************************
\******************************************************************************/

/*******************************************************************************
**
**  gckVGINTERRUPT_Construct
**
**  Construct an interrupt object.
**
**  INPUT:
**
**      Kernel
**          Pointer to the gckVGKERNEL object.
**
**  OUTPUT:
**
**      Interrupt
**          Pointer to the new gckVGINTERRUPT object.
*/

gceSTATUS
gckVGINTERRUPT_Construct(
    IN gckVGKERNEL Kernel,
    OUT gckVGINTERRUPT * Interrupt
    )
{
    gceSTATUS status;
    gckVGINTERRUPT interrupt = gcvNULL;

    gcmkHEADER_ARG("Kernel=0x%x Interrupt=0x%x", Kernel, Interrupt);

    /* Verify argeuments. */
    gcmkVERIFY_OBJECT(Kernel, gcvOBJ_KERNEL);
    gcmkVERIFY_ARGUMENT(Interrupt != gcvNULL);

    do
    {
        /* Allocate the gckVGINTERRUPT structure. */
        gcmkERR_BREAK(gckOS_Allocate(
            Kernel->os,
            gcmSIZEOF(struct _gckVGINTERRUPT),
            (gctPOINTER *) &interrupt
            ));

        /* Reset the object data. */
        gcmkVERIFY_OK(gckOS_ZeroMemory(
            interrupt, gcmSIZEOF(struct _gckVGINTERRUPT)
            ));

        /* Initialize the object. */
        interrupt->object.type = gcvOBJ_INTERRUPT;

        /* Initialize the object pointers. */
        interrupt->kernel = Kernel;
        interrupt->os     = Kernel->os;

        /* Initialize the current FIFO position. */
        interrupt->head = (gctUINT8)~0;
        interrupt->tail = (gctUINT8)~0;

        /* Start the thread. */
        gcmkERR_BREAK(_StartInterruptHandler(interrupt));

        /* Return interrupt object. */
        *Interrupt = interrupt;

        /* Success. */
        return gcvSTATUS_OK;
    }
    while (gcvFALSE);

    /* Roll back. */
    if (interrupt != gcvNULL)
    {
        /* Free the gckVGINTERRUPT structure. */
        gcmkVERIFY_OK(gckOS_Free(interrupt->os, interrupt));
    }

    /* Return the status. */
    return status;
}


/*******************************************************************************
**
**  gckVGINTERRUPT_Destroy
**
**  Destroy an interrupt object.
**
**  INPUT:
**
**      Interrupt
**          Pointer to the gckVGINTERRUPT object to destroy.
**
**  OUTPUT:
**
**      Nothing.
*/

gceSTATUS
gckVGINTERRUPT_Destroy(
    IN gckVGINTERRUPT Interrupt
    )
{
    gceSTATUS status;

    gcmkHEADER_ARG("Interrupt=0x%x", Interrupt);

    /* Verify the arguments. */
    gcmkVERIFY_OBJECT(Interrupt, gcvOBJ_INTERRUPT);

    do
    {
        /* Stop the interrupt thread. */
        gcmkERR_BREAK(_StopInterruptHandler(Interrupt));

        /* Mark the object as unknown. */
        Interrupt->object.type = gcvOBJ_UNKNOWN;

        /* Free the gckVGINTERRUPT structure. */
        gcmkERR_BREAK(gckOS_Free(Interrupt->os, Interrupt));
    }
    while (gcvFALSE);

    gcmkFOOTER();

    /* Return the status. */
    return status;
}


/*******************************************************************************
**
**  gckVGINTERRUPT_DumpState
**
**  Print the current state of the interrupt manager.
**
**  INPUT:
**
**      Interrupt
**          Pointer to a gckVGINTERRUPT object.
**
**  OUTPUT:
**
**      Nothing.
*/

#if gcvDEBUG
gceSTATUS
gckVGINTERRUPT_DumpState(
    IN gckVGINTERRUPT Interrupt
    )
{
    gcmkHEADER_ARG("Interrupt=0x%x", Interrupt);
    /* Verify the arguments. */
    gcmkVERIFY_OBJECT(Interrupt, gcvOBJ_INTERRUPT);

    /* Print the header. */
    gcmkTRACE_ZONE(
        gcvLEVEL_VERBOSE, gcvZONE_COMMAND,
        "%s: INTERRUPT OBJECT STATUS\n",
        __FUNCTION__
        );

    /* Print statistics. */
#if gcmENABLE_INTERRUPT_STATISTICS
    gcmkTRACE_ZONE(
        gcvLEVEL_VERBOSE, gcvZONE_COMMAND,
        "  Maximum number of FIFO items accumulated at a single time: %d\n",
        Interrupt->maxFifoItems
        );

    gcmkTRACE_ZONE(
        gcvLEVEL_VERBOSE, gcvZONE_COMMAND,
        "  Interrupt FIFO overflow happened times: %d\n",
        Interrupt->fifoOverflow
        );

    gcmkTRACE_ZONE(
        gcvLEVEL_VERBOSE, gcvZONE_COMMAND,
        "  Maximum number of interrupts simultaneously generated: %d\n",
        Interrupt->maxSimultaneous
        );

    gcmkTRACE_ZONE(
        gcvLEVEL_VERBOSE, gcvZONE_COMMAND,
        "  Number of times when there were multiple interrupts generated: %d\n",
        Interrupt->multipleCount
        );
#endif

    gcmkTRACE_ZONE(
        gcvLEVEL_VERBOSE, gcvZONE_COMMAND,
        "  The current number of entries in the FIFO: %d\n",
        Interrupt->fifoItems
        );

    /* Print the FIFO contents. */
    if (Interrupt->fifoItems != 0)
    {
        gctUINT8 index;
        gctUINT8 last;

        gcmkTRACE_ZONE(
            gcvLEVEL_VERBOSE, gcvZONE_COMMAND,
            "  FIFO current contents:\n"
            );

        /* Get the current pointers. */
        index = Interrupt->tail;
        last  = Interrupt->head;

        while (index != last)
        {
            /* Advance to the next entry. */
            index += 1;

            gcmkTRACE_ZONE(
                gcvLEVEL_VERBOSE, gcvZONE_COMMAND,
                "    %d: 0x%08X\n",
                index, Interrupt->fifo[index]
                );
        }
    }

    gcmkFOOTER_NO();
    /* Success. */
    return gcvSTATUS_OK;
}
#endif


/*******************************************************************************
**
**  gckVGINTERRUPT_Enable
**
**  Enable the specified interrupt.
**
**  INPUT:
**
**      Interrupt
**          Pointer to a gckVGINTERRUPT object.
**
**      Id
**          Pointer to the variable that holds the interrupt number to be
**          registered in range 0..31.
**          If the value is less then 0, gckVGINTERRUPT_Enable will attempt
**          to find an unused interrupt. If such interrupt is found, the number
**          will be assigned to the variable if the functuion call succeedes.
**
**      Handler
**          Pointer to the handler to register for the interrupt.
**
**  OUTPUT:
**
**      Nothing.
*/

gceSTATUS
gckVGINTERRUPT_Enable(
    IN gckVGINTERRUPT Interrupt,
    IN OUT gctINT32_PTR Id,
    IN gctINTERRUPT_HANDLER Handler
    )
{
    gceSTATUS status;
    gctINT32 i;

    gcmkHEADER_ARG("Interrupt=0x%x Id=0x%x Handler=0x%x", Interrupt, Id, Handler);

    /* Verify the arguments. */
    gcmkVERIFY_OBJECT(Interrupt, gcvOBJ_INTERRUPT);
    gcmkVERIFY_ARGUMENT(Id != gcvNULL);
    gcmkVERIFY_ARGUMENT(Handler != gcvNULL);

    do
    {
        /* See if we need to allocate an ID. */
        if (*Id < 0)
        {
            /* Find the first unused interrupt handler. */
            for (i = 0; i < gcmCOUNTOF(Interrupt->handlers); ++i)
            {
                if (Interrupt->handlers[i] == gcvNULL)
                {
                    break;
                }
            }

            /* No unused innterrupts? */
            if (i == gcmCOUNTOF(Interrupt->handlers))
            {
                status = gcvSTATUS_OUT_OF_RESOURCES;
                break;
            }

            /* Update the interrupt ID. */
            *Id = i;
        }

        /* Make sure the ID is in range. */
        else if (*Id >= gcmCOUNTOF(Interrupt->handlers))
        {
            status = gcvSTATUS_INVALID_ARGUMENT;
            break;
        }

        /* Set interrupt handler. */
        Interrupt->handlers[*Id] = Handler;

        /* Success. */
        status = gcvSTATUS_OK;
    }
    while (gcvFALSE);

    gcmkFOOTER();
    /* Return the status. */
    return status;
}


/*******************************************************************************
**
**  gckVGINTERRUPT_Disable
**
**  Disable the specified interrupt.
**
**  INPUT:
**
**      Interrupt
**          Pointer to a gckVGINTERRUPT object.
**
**      Id
**          Interrupt number to be disabled in range 0..31.
**
**  OUTPUT:
**
**      Nothing.
*/

gceSTATUS
gckVGINTERRUPT_Disable(
    IN gckVGINTERRUPT Interrupt,
    IN gctINT32 Id
    )
{
    gcmkHEADER_ARG("Interrupt=0x%x Id=0x%x", Interrupt, Id);
    /* Verify the arguments. */
    gcmkVERIFY_OBJECT(Interrupt, gcvOBJ_INTERRUPT);
    gcmkVERIFY_ARGUMENT((Id >= 0) && (Id < gcmCOUNTOF(Interrupt->handlers)));

    /* Reset interrupt handler. */
    Interrupt->handlers[Id] = gcvNULL;

    gcmkFOOTER_NO();
    /* Success. */
    return gcvSTATUS_OK;
}


/*******************************************************************************
**
**  gckVGINTERRUPT_Enque
**
**  Read the interrupt status register and put the value in the interrupt FIFO.
**
**  INPUT:
**
**      Interrupt
**          Pointer to a gckVGINTERRUPT object.
**
**  OUTPUT:
**
**      Nothing.
*/

gceSTATUS
gckVGINTERRUPT_Enque(
    IN gckVGINTERRUPT Interrupt
    )
{
    gceSTATUS status;
    gctUINT32 triggered;

    gcmkHEADER_ARG("Interrupt=0x%x", Interrupt);

    /* Verify the arguments. */
    gcmkVERIFY_OBJECT(Interrupt, gcvOBJ_INTERRUPT);

    do
    {
        /* Read interrupt status register. */
        gcmkERR_BREAK(gckVGHARDWARE_ReadInterrupt(
            Interrupt->kernel->hardware, &triggered
            ));

        /* No interrupts to process? */
        if (triggered == 0)
        {
            status = gcvSTATUS_NOT_OUR_INTERRUPT;
            break;
        }

        /* FIFO overflow? */
        if (Interrupt->fifoItems == gcmCOUNTOF(Interrupt->fifo))
        {
#if gcmENABLE_INTERRUPT_STATISTICS
            Interrupt->fifoOverflow += 1;
#endif

            /* OR the interrupt with the last value in the FIFO. */
            Interrupt->fifo[Interrupt->head] |= triggered;

            /* Success (kind of). */
            status = gcvSTATUS_OK;
        }
        else
        {
            /* Advance to the next entry. */
            Interrupt->head      += 1;
            Interrupt->fifoItems += 1;

#if gcmENABLE_INTERRUPT_STATISTICS
            if (Interrupt->fifoItems > Interrupt->maxFifoItems)
            {
                Interrupt->maxFifoItems = Interrupt->fifoItems;
            }
#endif

            /* Set the new value. */
            Interrupt->fifo[Interrupt->head] = triggered;

            /* Increment the FIFO semaphore. */
            gcmkERR_BREAK(gckOS_IncrementSemaphore(
                Interrupt->os, Interrupt->fifoValid
                ));

            /* Windows kills our threads prematurely when the application
               exists. Verify here that the thread is still alive. */
            status = gckOS_VerifyThread(Interrupt->os, Interrupt->handler);

            /* Has the thread been prematurely terminated? */
            if (status != gcvSTATUS_OK)
            {
                /* Process all accumulated interrupts. */
                while (Interrupt->head != Interrupt->tail)
                {
#if gcmENABLE_INTERRUPT_STATISTICS
                    /* Process the interrupt. */
                    _ProcessInterrupt(Interrupt, gcvNULL);
#else
                    /* Process the interrupt. */
                    _ProcessInterrupt(Interrupt);
#endif
                }

                /* Set success. */
                status = gcvSTATUS_OK;
            }
        }
    }
    while (gcvFALSE);

    gcmkFOOTER();
    /* Return status. */
    return status;
}

#endif /* gcdENABLE_VG */