Changeset af65b72 in mainline for uspace/srv/console/console.c


Ignore:
Timestamp:
2009-06-26T15:06:48Z (15 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1fbe064b
Parents:
1cab2f41
Message:

Do not use the pending mechanism in console.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/console/console.c

    r1cab2f41 raf65b72  
    5252#include <event.h>
    5353#include <devmap.h>
    54 #include <assert.h>
    5554#include <fibril_sync.h>
    5655
     
    10099} fb_pending;
    101100
    102 /** Pending input structure. */
    103 typedef struct {
    104         link_t link;
    105         console_t *cons;      /**< Console waiting for input */
    106         ipc_callid_t rid;     /**< Call ID waiting for input */
    107         ipc_callid_t callid;  /**< Call ID waiting for IPC_DATA_READ */
    108        
    109         size_t pos;           /**< Position of the last stored data */
    110         size_t size;          /**< Size of ther buffer */
    111         char *data;           /**< Already stored data */
    112 } pending_input_t;
    113 
    114 LIST_INITIALIZE(pending_input);
    115 
    116101static FIBRIL_MUTEX_INITIALIZE(input_mutex);
    117102static FIBRIL_CONDVAR_INITIALIZE(input_cv);
    118 static input_flag = false;
    119 
    120 /** Process pending input requests */
    121 static void process_pending_input(void)
    122 {
    123         link_t *cur;
    124        
    125 loop:
    126         fibril_mutex_lock(&input_mutex);
    127         while (!input_flag)
    128                 fibril_condvar_wait(&input_cv, &input_mutex);
    129 rescan:
    130         for (cur = pending_input.next; cur != &pending_input; cur = cur->next) {
    131                 pending_input_t *pr = list_get_instance(cur, pending_input_t, link);
    132                
    133                 console_event_t ev;
    134                 if (keybuffer_pop(&pr->cons->keybuffer, &ev)) {
    135                        
    136                         if (pr->data != NULL) {
    137                                 if (ev.type == KEY_PRESS) {
    138                                         pr->data[pr->pos] = ev.c;
    139                                         pr->pos++;
    140                                 }
    141                         } else {
    142                                 ipc_answer_4(pr->rid, EOK, ev.type, ev.key, ev.mods, ev.c);
    143                                 list_remove(cur);
    144                                 free(pr);
    145                                 goto rescan;
    146                         }
    147                 }
    148                
    149                 if ((pr->data != NULL) && (pr->pos == pr->size)) {
    150                         (void) ipc_data_read_finalize(pr->callid, pr->data, pr->size);
    151                         ipc_answer_1(pr->rid, EOK, pr->size);
    152 
    153                         free(pr->data);
    154                         list_remove(cur);
    155                         free(pr);
    156                         goto rescan;
    157                 }
    158         }
    159         input_flag = false;
    160         fibril_mutex_unlock(&input_mutex);
    161         goto loop;
    162 }
    163103
    164104static void curs_visibility(bool visible)
     
    462402                        fibril_mutex_lock(&input_mutex);
    463403                        keybuffer_push(&active_console->keybuffer, &ev);
    464                         input_flag = true;
    465                         fibril_condvar_signal(&input_cv);
     404                        fibril_condvar_broadcast(&input_cv);
    466405                        fibril_mutex_unlock(&input_mutex);
    467406                        break;
     
    528467        console_event_t ev;
    529468        fibril_mutex_lock(&input_mutex);
     469recheck:
    530470        while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) {
    531471                if (ev.type == KEY_PRESS) {
     
    540480                free(buf);
    541481        } else {
    542                 pending_input_t *pr = (pending_input_t *) malloc(sizeof(pending_input_t));
    543                 if (!pr) {
    544                         fibril_mutex_unlock(&input_mutex);
    545                         ipc_answer_0(callid, ENOMEM);
    546                         ipc_answer_0(rid, ENOMEM);
    547                         free(buf);
    548                         return;
    549                 }
    550                
    551                 pr->cons = cons;
    552                 pr->rid = rid;
    553                 pr->callid = callid;
    554                 pr->pos = pos;
    555                 pr->size = size;
    556                 pr->data = buf;
    557                 list_append(&pr->link, &pending_input);
     482                fibril_condvar_wait(&input_cv, &input_mutex);
     483                goto recheck;
    558484        }
    559485        fibril_mutex_unlock(&input_mutex);
     
    565491
    566492        fibril_mutex_lock(&input_mutex);
     493recheck:
    567494        if (keybuffer_pop(&cons->keybuffer, &ev)) {
    568495                ipc_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c);
    569496        } else {
    570                 pending_input_t *pr = (pending_input_t *) malloc(sizeof(pending_input_t));
    571                 if (!pr) {
    572                         fibril_mutex_unlock(&input_mutex);
    573                         ipc_answer_0(rid, ENOMEM);
    574                         return;
    575                 }
    576                
    577                 pr->cons = cons;
    578                 pr->rid = rid;
    579                 pr->callid = 0;
    580                 pr->data = NULL;
    581                 list_append(&pr->link, &pending_input);
     497                fibril_condvar_wait(&input_cv, &input_mutex);
     498                goto recheck;
    582499        }
    583500        fibril_mutex_unlock(&input_mutex);
     
    738655        async_new_connection(phonehash, 0, NULL, keyboard_events);
    739656
    740         fid_t fid = fibril_create(process_pending_input, NULL);
    741         if (!fid) {
    742                 printf(NAME ": Failed to create fibril for handling pending "
    743                     "input\n");
    744                 return -1;
    745         }
    746         fibril_add_ready(fid);
    747        
    748657        /* Connect to framebuffer driver */
    749658        fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
Note: See TracChangeset for help on using the changeset viewer.