Changeset 456f7ae in mainline


Ignore:
Timestamp:
2019-08-07T05:48:26Z (5 years ago)
Author:
Matthieu Riolo <matthieu.riolo@…>
Children:
035d7d8
Parents:
c675ab1
git-author:
Michal Koutný <xm.koutny+hos@…> (2015-10-20 23:25:18)
git-committer:
Matthieu Riolo <matthieu.riolo@…> (2019-08-07 05:48:26)
Message:

libc: Separated task event functions

Conflicts:

uspace/lib/c/Makefile
uspace/lib/c/include/task.h

Location:
uspace/lib/c
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    rc675ab1 r456f7ae  
    8282        generic/smc.c \
    8383        generic/task.c \
     84        generic/task_event.c \
    8485        generic/imath.c \
    8586        generic/inet/addr.c \
  • uspace/lib/c/generic/private/task.h

    rc675ab1 r456f7ae  
    4242int task_retval_internal(int, bool);
    4343
     44async_exch_t *taskman_exchange_begin(void);
     45
     46void taskman_exchange_end(async_exch_t *);
     47
    4448#endif
    4549
  • uspace/lib/c/generic/task.c

    rc675ab1 r456f7ae  
    5454
    5555static async_sess_t *session_taskman = NULL;
    56 static task_event_handler_t task_event_handler = NULL;
    5756
    5857task_id_t task_get_id(void)
     
    7069}
    7170
    72 static async_exch_t *taskman_exchange_begin(void)
     71async_exch_t *taskman_exchange_begin(void)
    7372{
    7473        /* Lazy connection */
     
    8988}
    9089
    91 static void taskman_exchange_end(async_exch_t *exch)
     90void taskman_exchange_end(async_exch_t *exch)
    9291{
    9392        async_exchange_end(exch);
     
    472471}
    473472
    474 // TODO extract to separate module
    475 static 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 
    488 static 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  */
    516 int 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 
    525         task_event_handler = 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;
    540 }
    541 
    542473void __task_init(async_sess_t *sess)
    543474{
  • uspace/lib/c/include/task.h

    rc675ab1 r456f7ae  
    7575
    7676extern errno_t task_retval(int);
     77
     78/* Implemented in task_event.h */
    7779extern int task_register_event_handler(task_event_handler_t);
    7880
Note: See TracChangeset for help on using the changeset viewer.