Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 44b7783 in mainline for kernel/generic/src/console/chardev.c


Ignore:
Timestamp:
2009-04-21T12:43:14Z (13 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
c2417bc
Parents:
d6d04e7
Message:

rename _getc() to indev_pop_character()
implicit creation of stdin via stdin_wire()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/chardev.c

    rd6d04e7 r44b7783  
    3636#include <synch/waitq.h>
    3737#include <synch/spinlock.h>
     38#include <print.h>
     39#include <func.h>
     40#include <arch.h>
    3841
    3942/** Initialize input character device.
     
    8083}
    8184
     85/** Pop character from input character device.
     86 *
     87 * @param indev Input character device.
     88 *
     89 * @return Character read.
     90 *
     91 */
     92wchar_t indev_pop_character(indev_t *indev)
     93{
     94        if (atomic_get(&haltstate)) {
     95                /* If we are here, we are hopefully on the processor that
     96                 * issued the 'halt' command, so proceed to read the character
     97                 * directly from input
     98                 */
     99                if (check_poll(indev))
     100                        return indev->op->poll(indev);
     101               
     102                /* No other way of interacting with user */
     103                interrupts_disable();
     104               
     105                if (CPU)
     106                        printf("cpu%u: ", CPU->id);
     107                else
     108                        printf("cpu: ");
     109               
     110                printf("halted (no polling input)\n");
     111                cpu_halt();
     112        }
     113       
     114        waitq_sleep(&indev->wq);
     115        ipl_t ipl = interrupts_disable();
     116        spinlock_lock(&indev->lock);
     117        wchar_t ch = indev->buffer[(indev->index - indev->counter) % INDEV_BUFLEN];
     118        indev->counter--;
     119        spinlock_unlock(&indev->lock);
     120        interrupts_restore(ipl);
     121       
     122        return ch;
     123}
     124
    82125/** Initialize output character device.
    83126 *
     
    94137}
    95138
     139bool check_poll(indev_t *indev)
     140{
     141        if (indev == NULL)
     142                return false;
     143       
     144        if (indev->op == NULL)
     145                return false;
     146       
     147        return (indev->op->poll != NULL);
     148}
     149
    96150/** @}
    97151 */
Note: See TracChangeset for help on using the changeset viewer.