00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <stdio.h>
00014
00015 #include <l4/l4con/l4con-client.h>
00016 #include <l4/l4con/l4con.h>
00017 #include <l4/log/l4log.h>
00018 #include <l4/sys/types.h>
00019 #include <l4/env/errno.h>
00020 #include <l4/util/macros.h>
00021 #include <l4/thread/thread.h>
00022 #include <l4/events/events.h>
00023
00024 #include "events.h"
00025
00026 #define DEBUG_EVENTS 0
00027
00028 static l4_threadid_t con_service_id;
00029
00030
00031
00032
00033 static void
00034 events_init_and_wait(void *dummy)
00035 {
00036 l4events_ch_t event_ch = L4EVENTS_EXIT_CHANNEL;
00037 l4events_nr_t event_nr = L4EVENTS_NO_NR;
00038 l4events_event_t event;
00039 CORBA_Environment _env = dice_default_environment;
00040
00041
00042 l4events_init();
00043 l4events_register(event_ch, _CON_EVENT_THREAD_PRIORITY);
00044
00045 LOGdL(DEBUG_EVENTS, "event thread up.");
00046
00047
00048 for (;;)
00049 {
00050 l4_threadid_t tid;
00051 int ret;
00052 long res;
00053
00054 res = l4events_give_ack_and_receive(&event_ch, &event, &event_nr,
00055 L4_IPC_NEVER, L4EVENTS_RECV_ACK);
00056 if (res != L4EVENTS_OK)
00057 {
00058 LOGdL(DEBUG_EVENTS, "Got bad event (result=%ld, %s)",
00059 res, l4env_errstr(res));
00060 continue;
00061 }
00062
00063 tid = *(l4_threadid_t*)event.str;
00064
00065 LOGdL(DEBUG_EVENTS, "Got exit event for "l4util_idfmt,
00066 l4util_idstr(tid));
00067
00068
00069
00070 ret = con_if_close_all_call(&con_service_id, &tid, &_env);
00071 if (ret || DICE_HAS_EXCEPTION(&_env))
00072 LOG_Error("handle exit event: call to service thread failed " \
00073 "(ret %d, exc %d)!", ret, DICE_EXCEPTION_MAJOR(&_env));
00074 }
00075 }
00076
00077
00078
00079
00080 void
00081 init_events(void)
00082 {
00083 static int events_init_done;
00084
00085 if (!events_init_done)
00086 {
00087 l4thread_t events_tid;
00088
00089 con_service_id = l4_myself();
00090 events_tid = l4thread_create_long(L4THREAD_INVALID_ID,
00091 events_init_and_wait,
00092 ".events", L4THREAD_INVALID_SP,
00093 L4THREAD_DEFAULT_SIZE,
00094 L4THREAD_DEFAULT_PRIO,
00095 0, L4THREAD_CREATE_ASYNC);
00096 LOGdL(DEBUG_EVENTS, "started event thread at "l4util_idfmt,
00097 l4util_idstr(l4thread_l4_id(events_tid)));
00098
00099 events_init_done = 1;
00100 }
00101 }