Changeset b8341bc in mainline


Ignore:
Timestamp:
2019-08-07T05:42:02Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
c675ab1
Parents:
b22b0a94
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-10-19 22:25:17)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-07 05:42:02)
Message:

taskman: IPC builerplate for task event API

  • Actual implementation tomorrow…

Conflicts:

uspace/lib/c/include/task.h

Location:
uspace
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/tester/proc/task_anywait.c

    rb22b0a94 rb8341bc  
    102102        int rc;
    103103
    104         task_set_event_handler(task_event_handler);
     104        rc = task_register_event_handler(task_event_handler);
     105        TASSERT(rc == EOK);
    105106
    106107        TPRINTF("1 exit only\n");
  • uspace/lib/c/generic/task.c

    rb22b0a94 rb8341bc  
    472472}
    473473
    474 void task_set_event_handler(task_event_handler_t handler)
    475 {
     474// TODO extract to separate module
     475static void taskman_task_event(ipc_callid_t iid, ipc_call_t *icall)
     476{
     477        task_id_t tid = (task_id_t)
     478            MERGE_LOUP32(IPC_GET_ARG1(*icall), IPC_GET_ARG2(*icall));
     479        int flags = IPC_GET_ARG3(*icall);
     480        task_exit_t texit = IPC_GET_ARG4(*icall);
     481        int retval = IPC_GET_ARG5(*icall);
     482
     483        task_event_handler(tid, flags, texit, retval);
     484
     485        async_answer_0(iid, EOK);
     486}
     487
     488static void taskman_event_conn(ipc_callid_t iid, ipc_call_t *icall, void *arg)
     489{
     490        /* Accept connection */
     491        async_answer_0(iid, EOK);
     492
     493        while (true) {
     494                ipc_call_t call;
     495                ipc_callid_t callid = async_get_call(&call);
     496
     497                if (!IPC_GET_IMETHOD(call)) {
     498                        /* Hangup, TODO explain or handle differntly */
     499                        break;
     500                }
     501
     502                switch (IPC_GET_IMETHOD(call)) {
     503                case TASKMAN_EV_TASK:
     504                        taskman_task_event(callid, &call);
     505                        break;
     506                default:
     507                        async_answer_0(callid, ENOTSUP);
     508                        break;
     509                }
     510        }
     511}
     512
     513/**
     514 * Blocks, calls handler in another fibril
     515 */
     516int task_register_event_handler(task_event_handler_t handler)
     517{
     518        /*
     519         * so far support assign once, modification cannot be naïve due to
     520         * races
     521         */
     522        assert(task_event_handler == NULL);
     523        assert(handler != NULL); /* no support for "unregistration" */
     524
    476525        task_event_handler = handler;
    477         // TODO implement logic for calling the handler
     526
     527        async_exch_t *exch = taskman_exchange_begin();
     528        aid_t req = async_send_0(exch, TASKMAN_EVENT_CALLBACK, NULL);
     529
     530        int rc = async_connect_to_me(exch, 0, 0, 0, taskman_event_conn, NULL);
     531        taskman_exchange_end(exch);
     532
     533        if (rc != EOK) {
     534                return rc;
     535        }
     536
     537        sysarg_t retval;
     538        async_wait_for(req, &retval);
     539        return retval;
    478540}
    479541
  • uspace/lib/c/include/ipc/taskman.h

    rb22b0a94 rb8341bc  
    4141typedef enum {
    4242        TASKMAN_WAIT = IPC_FIRST_USER_METHOD,
    43         TASKMAN_RETVAL
     43        TASKMAN_RETVAL,
     44        TASKMAN_EVENT_CALLBACK
    4445} taskman_request_t;
     46
     47typedef enum {
     48        TASKMAN_EV_TASK = IPC_FIRST_USER_METHOD
     49} taskman_event_t;
    4550
    4651typedef enum {
  • uspace/lib/c/include/task.h

    rb22b0a94 rb8341bc  
    7575
    7676extern errno_t task_retval(int);
    77 extern void task_set_event_handler(task_event_handler_t);
     77extern int task_register_event_handler(task_event_handler_t);
    7878
    7979#endif
  • uspace/srv/taskman/main.c

    rb22b0a94 rb8341bc  
    7979        async_exchange_end(exch);
    8080
    81         /* After forward we can dispose all session-related resources */
     81        /* After forward we can dispose all session-related resources
     82         * TODO later could be recycled for notification API
     83         */
    8284        async_hangup(sess_ref->sess);
    8385        free(sess_ref);
     
    118120        int rc = task_set_retval(icall);
    119121        async_answer_0(iid, rc);
     122}
     123
     124static void taskman_ctl_ev_callback(ipc_callid_t iid, ipc_call_t *icall)
     125{
     126        printf("%s:%i from %llu\n", __func__, __LINE__, icall->in_task_id);
     127        async_answer_0(iid, ENOTSUP); // TODO interrupt here
    120128}
    121129
     
    152160                case TASKMAN_RETVAL:
    153161                        taskman_ctl_retval(callid, &call);
     162                        break;
     163                case TASKMAN_EVENT_CALLBACK:
     164                        taskman_ctl_ev_callback(callid, &call);
    154165                        break;
    155166                default:
     
    223234        case TASKMAN_CONTROL:
    224235                control_connection(iid, icall);
    225                 // ---- interrupt here ----
    226                 //   implement control connection body (setup wait)
    227                 // ------------------------
    228236                break;
    229237        default:
Note: See TracChangeset for help on using the changeset viewer.