Changeset 953769f in mainline
- Timestamp:
- 2009-06-15T21:51:50Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 103e7d7
- Parents:
- ef8bcc6
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/async.c
ref8bcc6 r953769f 179 179 static void default_client_connection(ipc_callid_t callid, ipc_call_t *call); 180 180 static void default_interrupt_received(ipc_callid_t callid, ipc_call_t *call); 181 static void default_pending(void);182 181 183 182 /** … … 191 190 */ 192 191 static async_client_conn_t interrupt_received = default_interrupt_received; 193 194 /**195 * Pointer to a fibril function that will be used to handle pending196 * operations.197 */198 static async_pending_t pending = default_pending;199 192 200 193 static hash_table_t conn_hash_table; … … 376 369 377 370 fid_t fid = fibril_create(notification_fibril, msg); 378 fibril_add_ready(fid);379 380 futex_up(&async_futex);381 return true;382 }383 384 /** Pending fibril.385 *386 * After each call the pending operations are executed in a separate387 * fibril. The function pending() is c.388 *389 * @param arg Unused.390 *391 * @return Always zero.392 *393 */394 static int pending_fibril(void *arg)395 {396 pending();397 398 return 0;399 }400 401 /** Process pending actions.402 *403 * A new fibril is created which would process the pending operations.404 *405 * @return False if an error occured.406 * True if the execution was passed to the pending fibril.407 *408 */409 static bool process_pending(void)410 {411 futex_down(&async_futex);412 413 fid_t fid = fibril_create(pending_fibril, NULL);414 371 fibril_add_ready(fid); 415 372 … … 514 471 } 515 472 516 /** Default fibril function that gets called to handle pending operations.517 *518 * This function is defined as a weak symbol - to be redefined in user code.519 *520 */521 static void default_pending(void)522 {523 }524 525 473 /** Wrapper for client connection fibril. 526 474 * … … 661 609 662 610 out: 663 process_pending();611 ; 664 612 } 665 613 … … 1050 998 } 1051 999 1052 /** Setter for pending function pointer.1053 *1054 * @param pend Function that will implement a new pending1055 * operations fibril.1056 */1057 void async_set_pending(async_pending_t pend)1058 {1059 pending = pend;1060 }1061 1062 1000 /** Pseudo-synchronous message sending - fast version. 1063 1001 * -
uspace/lib/libc/include/async.h
ref8bcc6 r953769f 44 44 typedef ipc_callid_t aid_t; 45 45 typedef void (*async_client_conn_t)(ipc_callid_t callid, ipc_call_t *call); 46 typedef void (*async_pending_t)(void);47 46 48 47 extern atomic_t async_futex; … … 100 99 extern void async_set_client_connection(async_client_conn_t conn); 101 100 extern void async_set_interrupt_received(async_client_conn_t conn); 102 extern void async_set_pending(async_pending_t pend);103 101 104 102 /* Wrappers for simple communication */ -
uspace/srv/console/console.c
ref8bcc6 r953769f 52 52 #include <event.h> 53 53 #include <devmap.h> 54 #include <assert.h> 55 #include <fibril_sync.h> 54 56 55 57 #include "console.h" … … 112 114 LIST_INITIALIZE(pending_input); 113 115 116 static FIBRIL_MUTEX_INITIALIZE(input_mutex); 117 static FIBRIL_CONDVAR_INITIALIZE(input_cv); 118 static input_flag = false; 119 114 120 /** Process pending input requests */ 115 121 static void process_pending_input(void) 116 122 { 117 async_serialize_start();118 119 123 link_t *cur; 120 124 121 125 loop: 126 fibril_mutex_lock(&input_mutex); 127 while (!input_flag) 128 fibril_condvar_wait(&input_cv, &input_mutex); 129 rescan: 122 130 for (cur = pending_input.next; cur != &pending_input; cur = cur->next) { 123 131 pending_input_t *pr = list_get_instance(cur, pending_input_t, link); … … 133 141 } else { 134 142 ipc_answer_4(pr->rid, EOK, ev.type, ev.key, ev.mods, ev.c); 135 136 143 list_remove(cur); 137 144 free(pr); 138 139 goto loop; 145 goto rescan; 140 146 } 141 147 } … … 144 150 (void) ipc_data_read_finalize(pr->callid, pr->data, pr->size); 145 151 ipc_answer_1(pr->rid, EOK, pr->size); 146 152 147 153 free(pr->data); 148 154 list_remove(cur); 149 155 free(pr); 150 151 goto loop;152 153 }154 155 async_serialize_end();156 goto rescan; 157 } 158 } 159 input_flag = false; 160 fibril_mutex_unlock(&input_mutex); 161 goto loop; 156 162 } 157 163 … … 454 460 } 455 461 462 fibril_mutex_lock(&input_mutex); 456 463 keybuffer_push(&active_console->keybuffer, &ev); 464 input_flag = true; 465 fibril_condvar_signal(&input_cv); 466 fibril_mutex_unlock(&input_mutex); 457 467 break; 458 468 default: … … 515 525 } 516 526 517 async_serialize_start();518 519 527 size_t pos = 0; 520 528 console_event_t ev; 529 fibril_mutex_lock(&input_mutex); 521 530 while ((keybuffer_pop(&cons->keybuffer, &ev)) && (pos < size)) { 522 531 if (ev.type == KEY_PRESS) { … … 533 542 pending_input_t *pr = (pending_input_t *) malloc(sizeof(pending_input_t)); 534 543 if (!pr) { 544 fibril_mutex_unlock(&input_mutex); 535 545 ipc_answer_0(callid, ENOMEM); 536 546 ipc_answer_0(rid, ENOMEM); 537 547 free(buf); 538 async_serialize_end();539 548 return; 540 549 } … … 548 557 list_append(&pr->link, &pending_input); 549 558 } 550 551 async_serialize_end(); 559 fibril_mutex_unlock(&input_mutex); 552 560 } 553 561 554 562 static void cons_get_event(console_t *cons, ipc_callid_t rid, ipc_call_t *request) 555 563 { 556 async_serialize_start();557 558 564 console_event_t ev; 565 566 fibril_mutex_lock(&input_mutex); 559 567 if (keybuffer_pop(&cons->keybuffer, &ev)) { 560 568 ipc_answer_4(rid, EOK, ev.type, ev.key, ev.mods, ev.c); … … 562 570 pending_input_t *pr = (pending_input_t *) malloc(sizeof(pending_input_t)); 563 571 if (!pr) { 572 fibril_mutex_unlock(&input_mutex); 564 573 ipc_answer_0(rid, ENOMEM); 565 async_serialize_end();566 574 return; 567 575 } … … 573 581 list_append(&pr->link, &pending_input); 574 582 } 575 576 async_serialize_end(); 583 fibril_mutex_unlock(&input_mutex); 577 584 } 578 585 … … 716 723 static bool console_init(void) 717 724 { 718 async_serialize_start();719 720 725 /* Connect to keyboard driver */ 721 726 kbd_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_KEYBOARD, 0, 0); 722 727 if (kbd_phone < 0) { 723 728 printf(NAME ": Failed to connect to keyboard service\n"); 724 async_serialize_end();725 729 return false; 726 730 } … … 729 733 if (ipc_connect_to_me(kbd_phone, SERVICE_CONSOLE, 0, 0, &phonehash) != 0) { 730 734 printf(NAME ": Failed to create callback from keyboard service\n"); 731 async_serialize_end();732 735 return false; 733 736 } 734 737 735 async_set_pending(process_pending_input);736 738 async_new_connection(phonehash, 0, NULL, keyboard_events); 739 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); 737 747 738 748 /* Connect to framebuffer driver */ … … 740 750 if (fb_info.phone < 0) { 741 751 printf(NAME ": Failed to connect to video service\n"); 742 async_serialize_end();743 752 return -1; 744 753 } … … 748 757 if (rc < 0) { 749 758 printf(NAME ": Unable to register driver (%d)\n", rc); 750 async_serialize_end();751 759 return false; 752 760 } … … 784 792 fb_info.cols, fb_info.rows) == NULL) { 785 793 printf(NAME ": Unable to allocate screen buffer %u\n", i); 786 async_serialize_end();787 794 return false; 788 795 } … … 798 805 devmap_hangup_phone(DEVMAP_DRIVER); 799 806 printf(NAME ": Unable to register device %s\n", vc); 800 async_serialize_end();801 807 return false; 802 808 } … … 808 814 809 815 /* Initialize the screen */ 816 async_serialize_start(); 810 817 gcons_redraw_console(); 811 818 set_rgb_color(DEFAULT_FOREGROUND, DEFAULT_BACKGROUND); … … 813 820 curs_goto(0, 0); 814 821 curs_visibility(active_console->scr.is_cursor_visible); 822 async_serialize_end(); 815 823 816 824 /* Receive kernel notifications */ … … 820 828 async_set_interrupt_received(interrupt_received); 821 829 822 async_serialize_end();823 830 return true; 824 831 }
Note:
See TracChangeset
for help on using the changeset viewer.