ui/src/xvbt/XEventQueue.i3


Copyright (C) 1994, Digital Equipment Corp.
 by Steve Glassman, Mark Manasse and Greg Nelson 
<*PRAGMA LL*>

UNSAFE INTERFACE XEventQueue;   (* = RingBuffer(XEvent) *)
IMPORT X;

TYPE
  T = RECORD
        lo, hi: CARDINAL              := 0;
        buff  : REF ARRAY OF X.XEvent := NIL
      END;
buff[lo..hi-1] circularly are the active entries; lo = hi => the queue is empty; lo # hi => buff # NIL.

CONST Empty = T{0, 0, NIL};

<*INLINE*> PROCEDURE IsEmpty (READONLY rb: T): BOOLEAN;
Return whether rb is empty.

PROCEDURE Insert (VAR rb: T; READONLY e: X.XEvent);
Insert e into rb, extending rb if necessary.

EXCEPTION Exhausted;

PROCEDURE Remove (VAR rb: T): X.XEvent RAISES {Exhausted};
Raise the exception if rb is empty, else remove the oldest element of rb and return it.

PROCEDURE Peek (VAR rb: T): X.XEvent RAISES {Exhausted};
Like Remove, but leave the returned element at the head of the queue.

END XEventQueue.