/* * Wait for a keycode to arrive. * Uses the keyboard wait queue to sleep until * a keycode arrives. */ Keycode Wait_For_Key(void) { bool gotKey, iflag; Keycode keycode = KEY_UNKNOWN; // see if we still have input from the qemu command line to hand off keycode = Get_Test_Input(); if (keycode != KEY_UNKNOWN) { return keycode; } iflag = Begin_Int_Atomic(); do { gotKey = !Is_Queue_Empty(); if (gotKey) keycode = Dequeue_Keycode(); else Wait(&s_waitQueue); } while (!gotKey); End_Int_Atomic(iflag); return keycode; }
static __inline__ Keycode Dequeue_Keycode(void) { Keycode result; KASSERT(!Is_Queue_Empty()); result = s_queue[s_queueHead]; s_queueHead = NEXT(s_queueHead); return result; }
/* * Poll for a key event. * Returns true if a key is available, * false if not. If a key event is available, * it will be stored in the location pointed to * by keycode. */ bool Read_Key(Keycode * keycode) { bool result, iflag; iflag = Begin_Int_Atomic(); result = !Is_Queue_Empty(); if (result) { *keycode = Dequeue_Keycode(); } End_Int_Atomic(iflag); return result; }
/* * Wait for a keycode to arrive. * Uses the keyboard wait queue to sleep until * a keycode arrives. */ Keycode Wait_For_Key(void) { bool gotKey, iflag; Keycode keycode = KEY_UNKNOWN; iflag = Begin_Int_Atomic(); do { gotKey = !Is_Queue_Empty(); if (gotKey) keycode = Dequeue_Keycode(); else Wait(&s_waitQueue); } while (!gotKey); End_Int_Atomic(iflag); return keycode; }