Changeset 49d072e in mainline
- Timestamp:
- 2006-06-02T10:54:45Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bf9afa07
- Parents:
- 838c48e
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
fb/fb.c
r838c48e r49d072e 77 77 /* Auto-cursor position */ 78 78 int cursor_active, cur_col, cur_row; 79 int cursor_shown; 79 80 } viewport_t; 80 81 … … 396 397 } 397 398 399 static void cursor_hide(int vp) 400 { 401 viewport_t *vport = &viewports[vp]; 402 403 if (vport->cursor_active && vport->cursor_shown) { 404 invert_char(vp, vport->cur_row, vport->cur_col); 405 vport->cursor_shown = 0; 406 } 407 } 408 409 static void cursor_print(int vp) 410 { 411 viewport_t *vport = &viewports[vp]; 412 413 /* Do not check for cursor_shown */ 414 if (vport->cursor_active) { 415 invert_char(vp, vport->cur_row, vport->cur_col); 416 vport->cursor_shown = 1; 417 } 418 } 419 420 static void cursor_blink(int vp) 421 { 422 viewport_t *vport = &viewports[vp]; 423 424 if (vport->cursor_shown) 425 cursor_hide(vp); 426 else 427 cursor_print(vp); 428 } 429 398 430 /** Draw character at given position relative to viewport 399 431 * … … 407 439 viewport_t *vport = &viewports[vp]; 408 440 409 if (vport->cursor_active && (vport->cur_col != col || vport->cur_row != row)) 441 /* Optimize - do not hide cursor if we are going to overwrite it */ 442 if (vport->cursor_active && vport->cursor_shown && 443 (vport->cur_col != col || vport->cur_row != row)) 410 444 invert_char(vp, vport->cur_row, vport->cur_col); 411 445 … … 422 456 vport->cur_row--; 423 457 } 424 if (vport->cursor_active) 425 invert_char(vp, vport->cur_row, vport->cur_col); 458 cursor_print(vp); 426 459 } 427 460 … … 449 482 450 483 while (1) { 451 callid = async_get_call(&call); 484 callid = async_get_call_timeout(&call,250000); 485 if (!callid) { 486 cursor_blink(vp); 487 continue; 488 } 452 489 switch (IPC_GET_METHOD(call)) { 453 490 case IPC_M_PHONE_HUNGUP: … … 472 509 case FB_CLEAR: 473 510 clear_port(vp); 474 if (vport->cursor_active) 475 invert_char(vp, vport->cur_row, vport->cur_col); 511 cursor_print(vp); 476 512 retval = 0; 477 513 break; … … 484 520 } 485 521 retval = 0; 486 if (viewports[vp].cursor_active) { 487 invert_char(vp, vport->cur_row, vport->cur_col); 488 invert_char(vp, row, col); 489 } 522 cursor_hide(vp); 490 523 vport->cur_col = col; 491 524 vport->cur_row = row; 525 cursor_print(vp); 492 526 break; 493 527 case FB_CURSOR_VISIBILITY: 494 i = IPC_GET_ARG1(call); 528 cursor_hide(vp); 529 vport->cursor_active = IPC_GET_ARG1(call); 530 cursor_print(vp); 495 531 retval = 0; 496 if ((i && vport->cursor_active) || (!i && !vport->cursor_active))497 break;498 499 vport->cursor_active = i;500 invert_char(vp, vport->cur_row, vport->cur_col);501 532 break; 502 533 case FB_GET_CSIZE: … … 509 540 break; 510 541 } 511 if (vport->cursor_active) 512 invert_char(vp, vport->cur_row, vport->cur_col); 542 cursor_hide(vp); 513 543 scroll_port(vp, i); 514 if (vport->cursor_active) 515 invert_char(vp, vport->cur_row, vport->cur_col); 544 cursor_print(vp); 516 545 retval = 0; 517 546 break; … … 526 555 break; 527 556 } 557 cursor_hide(vp); 528 558 vp = i; 529 559 vport = &viewports[vp]; 560 cursor_print(vp); 530 561 retval = 0; 531 562 break; -
fb/sysio.c
r838c48e r49d072e 65 65 return; 66 66 67 snprintf(control, 20, "\033[%d;%df",row , col);67 snprintf(control, 20, "\033[%d;%df",row+1, col+1); 68 68 sysputs(control); 69 69 } -
libc/generic/async.c
r838c48e r49d072e 99 99 100 100 typedef struct { 101 struct timeval expires; /**< Expiration time for waiting thread */ 102 int inlist; /**< If true, this struct is in timeout list */ 103 link_t link; 104 101 105 pstid_t ptid; /**< Thread waiting for this message */ 102 106 int active; /**< If this thread is currently active */ 107 int timedout; /**< If true, we timed out */ 108 } awaiter_t; 109 110 typedef struct { 111 awaiter_t wdata; 112 103 113 int done; /**< If reply was received */ 104 114 ipc_call_t *dataptr; /**< Pointer where the answer data 105 * should be stored */ 106 struct timeval expires; /**< Expiration time for waiting thread */ 107 int has_timeout; /**< If true, this struct is in timeout list */ 108 link_t link; 109 115 * is stored */ 110 116 ipcarg_t retval; 111 117 } amsg_t; … … 118 124 119 125 typedef struct { 120 link_t link;121 ipcarg_t in_phone_hash; /**< Incoming phone hash. */ 122 link_t msg_queue; /**< Messages that should be delivered to this thread*/123 pstid_t ptid; /**< Thread associated with this connection*/124 int active; /**< If this thread is currently active*/126 awaiter_t wdata; 127 128 link_t link; /**< Hash table link */ 129 ipcarg_t in_phone_hash; /**< Incoming phone hash. */ 130 link_t msg_queue; /**< Messages that should be delivered to this thread */ 125 131 /* Structures for connection opening packet */ 126 132 ipc_callid_t callid; … … 209 215 }; 210 216 217 /** Insert sort timeout msg into timeouts list 218 * 219 * Assume async_futex is held 220 */ 221 static void insert_timeout(awaiter_t *wd) 222 { 223 link_t *tmp; 224 awaiter_t *cur; 225 226 wd->timedout = 0; 227 228 tmp = timeout_list.next; 229 while (tmp != &timeout_list) { 230 cur = list_get_instance(tmp, awaiter_t, link); 231 if (tv_gteq(&cur->expires, &wd->expires)) 232 break; 233 tmp = tmp->next; 234 } 235 list_append(&wd->link, tmp); 236 } 237 211 238 /*************************************************/ 212 239 … … 236 263 list_append(&msg->link, &conn->msg_queue); 237 264 238 if (!conn->active) { 239 conn->active = 1; 240 psthread_add_ready(conn->ptid); 265 /* If the call is waiting for event, run it */ 266 if (!conn->wdata.active) { 267 /* If in timeout list, remove it */ 268 if (conn->wdata.inlist) { 269 conn->wdata.inlist = 0; 270 list_remove(&conn->wdata.link); 271 } 272 conn->wdata.active = 1; 273 psthread_add_ready(conn->wdata.ptid); 241 274 } 242 275 … … 247 280 248 281 /** Return new incoming message for current(thread-local) connection */ 249 ipc_callid_t async_get_call (ipc_call_t *call)282 ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs) 250 283 { 251 284 msg_t *msg; … … 256 289 futex_down(&async_futex); 257 290 291 if (usecs) { 292 gettimeofday(&PS_connection->wdata.expires, NULL); 293 tv_add(&PS_connection->wdata.expires, usecs); 294 } else { 295 PS_connection->wdata.inlist = 0; 296 } 258 297 /* If nothing in queue, wait until something appears */ 259 if (list_empty(&PS_connection->msg_queue)) { 260 PS_connection->active = 0; 298 while (list_empty(&PS_connection->msg_queue)) { 299 if (usecs) { 300 PS_connection->wdata.inlist = 1; 301 insert_timeout(&PS_connection->wdata); 302 } 303 PS_connection->wdata.active = 0; 261 304 psthread_schedule_next_adv(PS_TO_MANAGER); 305 /* Futex is up after getting back from async_manager 306 * get it again */ 307 futex_down(&async_futex); 308 if (usecs && PS_connection->wdata.timedout && \ 309 list_empty(&PS_connection->msg_queue)) { 310 /* If we timed out-> exit */ 311 futex_up(&async_futex); 312 return 0; 313 } 262 314 } 263 315 … … 351 403 conn->in_phone_hash = in_phone_hash; 352 404 list_initialize(&conn->msg_queue); 353 conn->ptid = psthread_create(connection_thread, conn);354 405 conn->callid = callid; 355 406 if (call) 356 407 conn->call = *call; 357 conn-> active = 1; /* We will activate it asap */408 conn->wdata.active = 1; /* We will activate it asap */ 358 409 conn->cthread = cthread; 359 list_initialize(&conn->link); 360 if (!conn->ptid) { 410 411 conn->wdata.ptid = psthread_create(connection_thread, conn); 412 if (!conn->wdata.ptid) { 361 413 free(conn); 362 414 ipc_answer_fast(callid, ENOMEM, 0, 0); 363 415 return NULL; 364 416 } 417 /* Add connection to hash table */ 365 418 key = conn->in_phone_hash; 366 419 futex_down(&async_futex); 367 /* Add connection to hash table */368 420 hash_table_insert(&conn_hash_table, &key, &conn->link); 369 421 futex_up(&async_futex); 370 422 371 psthread_add_ready(conn-> ptid);372 373 return conn-> ptid;423 psthread_add_ready(conn->wdata.ptid); 424 425 return conn->wdata.ptid; 374 426 } 375 427 … … 400 452 { 401 453 struct timeval tv; 402 a msg_t *amsg;454 awaiter_t *waiter; 403 455 link_t *cur; 404 456 … … 408 460 cur = timeout_list.next; 409 461 while (cur != &timeout_list) { 410 amsg = list_get_instance(cur,amsg_t,link);411 if (tv_gt(& amsg->expires, &tv))462 waiter = list_get_instance(cur,awaiter_t,link); 463 if (tv_gt(&waiter->expires, &tv)) 412 464 break; 413 465 cur = cur->next; 414 list_remove(&amsg->link); 415 amsg->has_timeout = 0; 466 list_remove(&waiter->link); 467 waiter->inlist = 0; 468 waiter->timedout = 1; 416 469 /* Redundant condition? The thread should not 417 470 * be active when it gets here. 418 471 */ 419 if (! amsg->active) {420 amsg->active = 1;421 psthread_add_ready( amsg->ptid);472 if (!waiter->active) { 473 waiter->active = 1; 474 psthread_add_ready(waiter->ptid); 422 475 } 423 476 } … … 432 485 ipc_callid_t callid; 433 486 int timeout; 434 a msg_t *amsg;487 awaiter_t *waiter; 435 488 struct timeval tv; 436 489 … … 444 497 futex_down(&async_futex); 445 498 if (!list_empty(&timeout_list)) { 446 amsg = list_get_instance(timeout_list.next,amsg_t,link);499 waiter = list_get_instance(timeout_list.next,awaiter_t,link); 447 500 gettimeofday(&tv,NULL); 448 if (tv_gteq(&tv, & amsg->expires)) {501 if (tv_gteq(&tv, &waiter->expires)) { 449 502 handle_expired_timeouts(); 450 503 continue; 451 504 } else 452 timeout = tv_sub(& amsg->expires, &tv);505 timeout = tv_sub(&waiter->expires, &tv); 453 506 } else 454 507 timeout = SYNCH_NO_TIMEOUT; … … 528 581 write_barrier(); 529 582 /* Remove message from timeout list */ 530 if (msg-> has_timeout)531 list_remove(&msg-> link);583 if (msg->wdata.inlist) 584 list_remove(&msg->wdata.link); 532 585 msg->done = 1; 533 if (! msg-> active) {534 msg-> active = 1;535 psthread_add_ready(msg-> ptid);586 if (! msg->wdata.active) { 587 msg->wdata.active = 1; 588 psthread_add_ready(msg->wdata.ptid); 536 589 } 537 590 futex_up(&async_futex); … … 549 602 550 603 msg = malloc(sizeof(*msg)); 551 msg->active = 1;552 604 msg->done = 0; 553 605 msg->dataptr = dataptr; 606 607 msg->wdata.active = 1; /* We may sleep in next method, but it 608 * will use it's own mechanism */ 554 609 ipc_call_async_2(phoneid,method,arg1,arg2,msg,reply_received); 555 610 … … 575 630 } 576 631 577 msg-> ptid = psthread_get_id();578 msg-> active = 0;579 msg-> has_timeout = 0;632 msg->wdata.ptid = psthread_get_id(); 633 msg->wdata.active = 0; 634 msg->wdata.inlist = 0; 580 635 /* Leave locked async_futex when entering this function */ 581 636 psthread_schedule_next_adv(PS_TO_MANAGER); … … 587 642 } 588 643 589 /** Insert sort timeout msg into timeouts list590 *591 * Assume async_futex is held592 */593 static void insert_timeout(amsg_t *msg)594 {595 link_t *tmp;596 amsg_t *cur;597 598 tmp = timeout_list.next;599 while (tmp != &timeout_list) {600 cur = list_get_instance(tmp, amsg_t, link);601 if (tv_gteq(&cur->expires, &msg->expires))602 break;603 tmp = tmp->next;604 }605 list_append(&msg->link, tmp);606 }607 608 644 /** Wait for a message sent by async framework with timeout 609 645 * … … 626 662 } 627 663 628 msg->ptid = psthread_get_id(); 629 msg->active = 0; 630 msg->has_timeout = 1; 631 632 gettimeofday(&msg->expires, NULL); 633 tv_add(&msg->expires, timeout); 634 insert_timeout(msg); 664 gettimeofday(&msg->wdata.expires, NULL); 665 tv_add(&msg->wdata.expires, timeout); 666 667 msg->wdata.ptid = psthread_get_id(); 668 msg->wdata.active = 0; 669 msg->wdata.inlist = 1; 670 671 insert_timeout(&msg->wdata); 635 672 636 673 /* Leave locked async_futex when entering this function */ … … 661 698 return; 662 699 663 msg-> ptid = psthread_get_id();664 msg-> active = 0;665 msg-> has_timeout = 1;666 667 gettimeofday(&msg-> expires, NULL);668 tv_add(&msg-> expires, timeout);669 670 futex_down(&async_futex); 671 insert_timeout( msg);700 msg->wdata.ptid = psthread_get_id(); 701 msg->wdata.inlist = 1; 702 msg->wdata.active = 0; 703 704 gettimeofday(&msg->wdata.expires, NULL); 705 tv_add(&msg->wdata.expires, timeout); 706 707 futex_down(&async_futex); 708 insert_timeout(&msg->wdata); 672 709 /* Leave locked async_futex when entering this function */ 673 710 psthread_schedule_next_adv(PS_TO_MANAGER); -
libc/include/async.h
r838c48e r49d072e 39 39 40 40 int async_manager(void); 41 ipc_callid_t async_get_call(ipc_call_t *data); 42 41 ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs); 42 static inline ipc_callid_t async_get_call(ipc_call_t *data) 43 { 44 return async_get_call_timeout(data, 0); 45 } 43 46 44 47 aid_t async_send_2(int phoneid, ipcarg_t method, ipcarg_t arg1, ipcarg_t arg2,
Note:
See TracChangeset
for help on using the changeset viewer.