Changeset af65b72 in mainline
- Timestamp:
- 2009-06-26T15:06:48Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1fbe064b
- Parents:
- 1cab2f41
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/console/console.c
r1cab2f41 raf65b72 52 52 #include <event.h> 53 53 #include <devmap.h> 54 #include <assert.h>55 54 #include <fibril_sync.h> 56 55 … … 100 99 } fb_pending; 101 100 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 116 101 static FIBRIL_MUTEX_INITIALIZE(input_mutex); 117 102 static 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 }163 103 164 104 static void curs_visibility(bool visible) … … 462 402 fibril_mutex_lock(&input_mutex); 463 403 keybuffer_push(&active_console->keybuffer, &ev); 464 input_flag = true; 465 fibril_condvar_signal(&input_cv); 404 fibril_condvar_broadcast(&input_cv); 466 405 fibril_mutex_unlock(&input_mutex); 467 406 break; … … 528 467 console_event_t ev; 529 468 fibril_mutex_lock(&input_mutex); 469 recheck: 530 470 while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) { 531 471 if (ev.type == KEY_PRESS) { … … 540 480 free(buf); 541 481 } 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; 558 484 } 559 485 fibril_mutex_unlock(&input_mutex); … … 565 491 566 492 fibril_mutex_lock(&input_mutex); 493 recheck: 567 494 if (keybuffer_pop(&cons->keybuffer, &ev)) { 568 495 ipc_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c); 569 496 } 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; 582 499 } 583 500 fibril_mutex_unlock(&input_mutex); … … 738 655 async_new_connection(phonehash, 0, NULL, keyboard_events); 739 656 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 748 657 /* Connect to framebuffer driver */ 749 658 fb_info.phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_VIDEO, 0, 0);
Note:
See TracChangeset
for help on using the changeset viewer.