Rev 4173 | Rev 4490 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4173 | Rev 4252 | ||
---|---|---|---|
Line 29... | Line 29... | ||
29 | /** @addtogroup generic |
29 | /** @addtogroup generic |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** |
32 | /** |
33 | * @file |
33 | * @file |
34 | * @brief Kernel event notifications. |
34 | * @brief Kernel event notifications. |
35 | */ |
35 | */ |
36 | 36 | ||
37 | #include <event/event.h> |
37 | #include <ipc/event.h> |
38 | #include <event/event_types.h> |
38 | #include <ipc/event_types.h> |
39 | #include <mm/slab.h> |
39 | #include <mm/slab.h> |
40 | #include <arch/types.h> |
40 | #include <arch/types.h> |
41 | #include <synch/spinlock.h> |
41 | #include <synch/spinlock.h> |
42 | #include <console/console.h> |
42 | #include <console/console.h> |
43 | #include <memstr.h> |
43 | #include <memstr.h> |
Line 47... | Line 47... | ||
47 | /** |
47 | /** |
48 | * The events array. |
48 | * The events array. |
49 | * Arranging the events in this two-dimensional array should decrease the |
49 | * Arranging the events in this two-dimensional array should decrease the |
50 | * likelyhood of cacheline ping-pong. |
50 | * likelyhood of cacheline ping-pong. |
51 | */ |
51 | */ |
52 | static event_t *events[EVENT_END]; |
52 | static event_t events[EVENT_END]; |
53 | 53 | ||
54 | /** Initialize kernel events. */ |
54 | /** Initialize kernel events. */ |
55 | void event_init(void) |
55 | void event_init(void) |
56 | { |
56 | { |
57 | int i; |
57 | unsigned int i; |
58 | 58 | ||
59 | for (i = 0; i < EVENT_END; i++) { |
59 | for (i = 0; i < EVENT_END; i++) { |
60 | events[i] = (event_t *) malloc(sizeof(event_t), 0); |
- | |
61 | spinlock_initialize(&events[i]->lock, "event.lock"); |
60 | spinlock_initialize(&events[i].lock, "event.lock"); |
62 | events[i]->answerbox = NULL; |
61 | events[i].answerbox = NULL; |
63 | events[i]->counter = 0; |
62 | events[i].counter = 0; |
64 | events[i]->method = 0; |
63 | events[i].method = 0; |
65 | } |
64 | } |
66 | } |
65 | } |
67 | 66 | ||
68 | static int |
67 | static int |
69 | event_subscribe(event_type_t e, unative_t method, answerbox_t *answerbox) |
68 | event_subscribe(event_type_t evno, unative_t method, answerbox_t *answerbox) |
70 | { |
69 | { |
71 | if (e >= EVENT_END) |
70 | if (evno >= EVENT_END) |
72 | return ELIMIT; |
71 | return ELIMIT; |
73 | 72 | ||
74 | int res = EEXISTS; |
- | |
75 | event_t *event = events[e]; |
73 | spinlock_lock(&events[evno].lock); |
76 | 74 | ||
77 | spinlock_lock(&event->lock); |
75 | int res; |
- | 76 | ||
78 | if (!event->answerbox) { |
77 | if (events[evno].answerbox == NULL) { |
79 | event->answerbox = answerbox; |
78 | events[evno].answerbox = answerbox; |
80 | event->method = method; |
79 | events[evno].method = method; |
81 | event->counter = 0; |
80 | events[evno].counter = 0; |
82 | res = EOK; |
81 | res = EOK; |
- | 82 | } else |
|
- | 83 | res = EEXISTS; |
|
83 | } |
84 | |
84 | spinlock_unlock(&event->lock); |
85 | spinlock_unlock(&events[evno].lock); |
85 | 86 | ||
86 | return res; |
87 | return res; |
87 | } |
88 | } |
88 | 89 | ||
89 | unative_t sys_event_subscribe(unative_t evno, unative_t method) |
90 | unative_t sys_event_subscribe(unative_t evno, unative_t method) |
90 | { |
91 | { |
91 | return (unative_t) event_subscribe((event_type_t) evno, (unative_t) |
92 | return (unative_t) event_subscribe((event_type_t) evno, (unative_t) |
92 | method, &TASK->answerbox); |
93 | method, &TASK->answerbox); |
93 | } |
94 | } |
94 | 95 | ||
95 | bool event_is_subscribed(event_type_t e) |
96 | bool event_is_subscribed(event_type_t evno) |
96 | { |
97 | { |
97 | bool res; |
98 | bool res; |
98 | 99 | ||
99 | ASSERT(e < EVENT_END); |
100 | ASSERT(evno < EVENT_END); |
- | 101 | ||
100 | spinlock_lock(&events[e]->lock); |
102 | spinlock_lock(&events[evno].lock); |
101 | res = events[e]->answerbox != NULL; |
103 | res = events[evno].answerbox != NULL; |
102 | spinlock_unlock(&events[e]->lock); |
104 | spinlock_unlock(&events[evno].lock); |
103 | 105 | ||
104 | return res; |
106 | return res; |
105 | } |
107 | } |
106 | 108 | ||
107 | 109 | ||
108 | void event_cleanup_answerbox(answerbox_t *answerbox) |
110 | void event_cleanup_answerbox(answerbox_t *answerbox) |
109 | { |
111 | { |
110 | int i; |
112 | unsigned int i; |
111 | 113 | ||
112 | for (i = 0; i < EVENT_END; i++) { |
114 | for (i = 0; i < EVENT_END; i++) { |
113 | spinlock_lock(&events[i]->lock); |
115 | spinlock_lock(&events[i].lock); |
114 | if (events[i]->answerbox == answerbox) { |
116 | if (events[i].answerbox == answerbox) { |
115 | events[i]->answerbox = NULL; |
117 | events[i].answerbox = NULL; |
116 | events[i]->counter = 0; |
118 | events[i].counter = 0; |
117 | events[i]->method = 0; |
119 | events[i].method = 0; |
118 | } |
120 | } |
119 | spinlock_unlock(&events[i]->lock); |
121 | spinlock_unlock(&events[i].lock); |
120 | } |
122 | } |
121 | } |
123 | } |
122 | 124 | ||
123 | void |
125 | void |
124 | event_notify(event_type_t e, unative_t a1, unative_t a2, unative_t a3, |
126 | event_notify(event_type_t evno, unative_t a1, unative_t a2, unative_t a3, |
125 | unative_t a4, unative_t a5) |
127 | unative_t a4, unative_t a5) |
126 | { |
128 | { |
127 | ASSERT(e < EVENT_END); |
129 | ASSERT(evno < EVENT_END); |
128 | event_t *event = events[e]; |
- | |
- | 130 | ||
129 | spinlock_lock(&event->lock); |
131 | spinlock_lock(&events[evno].lock); |
130 | if (event->answerbox) { |
132 | if (events[evno].answerbox != NULL) { |
131 | call_t *call = ipc_call_alloc(FRAME_ATOMIC); |
133 | call_t *call = ipc_call_alloc(FRAME_ATOMIC); |
132 | if (call) { |
134 | if (call) { |
133 | call->flags |= IPC_CALL_NOTIF; |
135 | call->flags |= IPC_CALL_NOTIF; |
134 | call->priv = ++event->counter; |
136 | call->priv = ++events[evno].counter; |
135 | IPC_SET_METHOD(call->data, event->method); |
137 | IPC_SET_METHOD(call->data, events[evno].method); |
136 | IPC_SET_ARG1(call->data, a1); |
138 | IPC_SET_ARG1(call->data, a1); |
137 | IPC_SET_ARG2(call->data, a2); |
139 | IPC_SET_ARG2(call->data, a2); |
138 | IPC_SET_ARG3(call->data, a3); |
140 | IPC_SET_ARG3(call->data, a3); |
139 | IPC_SET_ARG4(call->data, a4); |
141 | IPC_SET_ARG4(call->data, a4); |
140 | IPC_SET_ARG5(call->data, a5); |
142 | IPC_SET_ARG5(call->data, a5); |
141 | 143 | ||
142 | spinlock_lock(&event->answerbox->irq_lock); |
144 | spinlock_lock(&events[evno].answerbox->irq_lock); |
143 | list_append(&call->link, &event->answerbox->irq_notifs); |
145 | list_append(&call->link, &events[evno].answerbox->irq_notifs); |
144 | spinlock_unlock(&event->answerbox->irq_lock); |
146 | spinlock_unlock(&events[evno].answerbox->irq_lock); |
145 | 147 | ||
146 | waitq_wakeup(&event->answerbox->wq, WAKEUP_FIRST); |
148 | waitq_wakeup(&events[evno].answerbox->wq, WAKEUP_FIRST); |
147 | } |
149 | } |
148 | } |
150 | } |
149 | spinlock_unlock(&event->lock); |
151 | spinlock_unlock(&events[evno].lock); |
150 | } |
152 | } |
151 | 153 | ||
152 | /** @} |
154 | /** @} |
153 | */ |
155 | */ |