Changeset 49d072e in mainline


Ignore:
Timestamp:
2006-06-02T10:54:45Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bf9afa07
Parents:
838c48e
Message:

Added blinking cursor.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • fb/fb.c

    r838c48e r49d072e  
    7777        /* Auto-cursor position */
    7878        int cursor_active, cur_col, cur_row;
     79        int cursor_shown;
    7980} viewport_t;
    8081
     
    396397}
    397398
     399static 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
     409static 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
     420static 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
    398430/** Draw character at given position relative to viewport
    399431 *
     
    407439        viewport_t *vport = &viewports[vp];
    408440
    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))
    410444                invert_char(vp, vport->cur_row, vport->cur_col);
    411445       
     
    422456                        vport->cur_row--;
    423457        }
    424         if (vport->cursor_active)
    425                 invert_char(vp, vport->cur_row, vport->cur_col);
     458        cursor_print(vp);
    426459}
    427460
     
    449482
    450483        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                }
    452489                switch (IPC_GET_METHOD(call)) {
    453490                case IPC_M_PHONE_HUNGUP:
     
    472509                case FB_CLEAR:
    473510                        clear_port(vp);
    474                         if (vport->cursor_active)
    475                                 invert_char(vp, vport->cur_row, vport->cur_col);
     511                        cursor_print(vp);
    476512                        retval = 0;
    477513                        break;
     
    484520                        }
    485521                        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);
    490523                        vport->cur_col = col;
    491524                        vport->cur_row = row;
     525                        cursor_print(vp);
    492526                        break;
    493527                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);
    495531                        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);
    501532                        break;
    502533                case FB_GET_CSIZE:
     
    509540                                break;
    510541                        }
    511                         if (vport->cursor_active)
    512                                 invert_char(vp, vport->cur_row, vport->cur_col);
     542                        cursor_hide(vp);
    513543                        scroll_port(vp, i);
    514                         if (vport->cursor_active)
    515                                 invert_char(vp, vport->cur_row, vport->cur_col);
     544                        cursor_print(vp);
    516545                        retval = 0;
    517546                        break;
     
    526555                                break;
    527556                        }
     557                        cursor_hide(vp);
    528558                        vp = i;
    529559                        vport = &viewports[vp];
     560                        cursor_print(vp);
    530561                        retval = 0;
    531562                        break;
  • fb/sysio.c

    r838c48e r49d072e  
    6565                return;
    6666
    67         snprintf(control, 20, "\033[%d;%df",row, col);
     67        snprintf(control, 20, "\033[%d;%df",row+1, col+1);
    6868        sysputs(control);
    6969}
  • libc/generic/async.c

    r838c48e r49d072e  
    9999
    100100typedef 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
    101105        pstid_t ptid;                /**< Thread waiting for this message */
    102106        int active;                  /**< If this thread is currently active */
     107        int timedout;                /**< If true, we timed out */
     108} awaiter_t;
     109
     110typedef struct {
     111        awaiter_t wdata;
     112
    103113        int done;                    /**< If reply was received */
    104114        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 */
    110116        ipcarg_t retval;
    111117} amsg_t;
     
    118124
    119125typedef 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 */
    125131        /* Structures for connection opening packet */
    126132        ipc_callid_t callid;
     
    209215};
    210216
     217/** Insert sort timeout msg into timeouts list
     218 *
     219 * Assume async_futex is held
     220 */
     221static 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
    211238/*************************************************/
    212239
     
    236263        list_append(&msg->link, &conn->msg_queue);
    237264       
    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);
    241274        }
    242275
     
    247280
    248281/** Return new incoming message for current(thread-local) connection */
    249 ipc_callid_t async_get_call(ipc_call_t *call)
     282ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs)
    250283{
    251284        msg_t *msg;
     
    256289        futex_down(&async_futex);
    257290
     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        }
    258297        /* 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;
    261304                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                }
    262314        }
    263315       
     
    351403        conn->in_phone_hash = in_phone_hash;
    352404        list_initialize(&conn->msg_queue);
    353         conn->ptid = psthread_create(connection_thread, conn);
    354405        conn->callid = callid;
    355406        if (call)
    356407                conn->call = *call;
    357         conn->active = 1; /* We will activate it asap */
     408        conn->wdata.active = 1; /* We will activate it asap */
    358409        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) {
    361413                free(conn);
    362414                ipc_answer_fast(callid, ENOMEM, 0, 0);
    363415                return NULL;
    364416        }
     417        /* Add connection to hash table */
    365418        key = conn->in_phone_hash;
    366419        futex_down(&async_futex);
    367         /* Add connection to hash table */
    368420        hash_table_insert(&conn_hash_table, &key, &conn->link);
    369421        futex_up(&async_futex);
    370422
    371         psthread_add_ready(conn->ptid);
    372 
    373         return conn->ptid;
     423        psthread_add_ready(conn->wdata.ptid);
     424
     425        return conn->wdata.ptid;
    374426}
    375427
     
    400452{
    401453        struct timeval tv;
    402         amsg_t *amsg;
     454        awaiter_t *waiter;
    403455        link_t *cur;
    404456
     
    408460        cur = timeout_list.next;
    409461        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))
    412464                        break;
    413465                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;
    416469                /* Redundant condition? The thread should not
    417470                 * be active when it gets here.
    418471                 */
    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);
    422475                }
    423476        }
     
    432485        ipc_callid_t callid;
    433486        int timeout;
    434         amsg_t *amsg;
     487        awaiter_t *waiter;
    435488        struct timeval tv;
    436489
     
    444497                futex_down(&async_futex);
    445498                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);
    447500                        gettimeofday(&tv,NULL);
    448                         if (tv_gteq(&tv, &amsg->expires)) {
     501                        if (tv_gteq(&tv, &waiter->expires)) {
    449502                                handle_expired_timeouts();
    450503                                continue;
    451504                        } else
    452                                 timeout = tv_sub(&amsg->expires, &tv);
     505                                timeout = tv_sub(&waiter->expires, &tv);
    453506                } else
    454507                        timeout = SYNCH_NO_TIMEOUT;
     
    528581        write_barrier();
    529582        /* 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);
    532585        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);
    536589        }
    537590        futex_up(&async_futex);
     
    549602
    550603        msg = malloc(sizeof(*msg));
    551         msg->active = 1;
    552604        msg->done = 0;
    553605        msg->dataptr = dataptr;
     606
     607        msg->wdata.active = 1; /* We may sleep in next method, but it
     608                                * will use it's own mechanism */
    554609        ipc_call_async_2(phoneid,method,arg1,arg2,msg,reply_received);
    555610
     
    575630        }
    576631
    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;
    580635        /* Leave locked async_futex when entering this function */
    581636        psthread_schedule_next_adv(PS_TO_MANAGER);
     
    587642}
    588643
    589 /** Insert sort timeout msg into timeouts list
    590  *
    591  * Assume async_futex is held
    592  */
    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 
    608644/** Wait for a message sent by async framework with timeout
    609645 *
     
    626662        }
    627663
    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);
    635672
    636673        /* Leave locked async_futex when entering this function */
     
    661698                return;
    662699
    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);
    672709        /* Leave locked async_futex when entering this function */
    673710        psthread_schedule_next_adv(PS_TO_MANAGER);
  • libc/include/async.h

    r838c48e r49d072e  
    3939
    4040int async_manager(void);
    41 ipc_callid_t async_get_call(ipc_call_t *data);
    42 
     41ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs);
     42static inline ipc_callid_t async_get_call(ipc_call_t *data)
     43{
     44        return async_get_call_timeout(data, 0);
     45}
    4346
    4447aid_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.