Changeset 13a638d in mainline for kernel/generic/src/ipc/event.c
- Timestamp:
- 2009-04-06T19:32:22Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade
- Children:
- 3636964
- Parents:
- 149d14e5
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/ipc/event.c
r149d14e5 r13a638d 32 32 /** 33 33 * @file 34 * @brief 34 * @brief Kernel event notifications. 35 35 */ 36 36 37 #include < event/event.h>38 #include < event/event_types.h>37 #include <ipc/event.h> 38 #include <ipc/event_types.h> 39 39 #include <mm/slab.h> 40 40 #include <arch/types.h> … … 50 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 54 /** Initialize kernel events. */ 55 55 void event_init(void) 56 56 { 57 int i;58 57 unsigned int i; 58 59 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"); 62 events[i]->answerbox = NULL; 63 events[i]->counter = 0; 64 events[i]->method = 0; 60 spinlock_initialize(&events[i].lock, "event.lock"); 61 events[i].answerbox = NULL; 62 events[i].counter = 0; 63 events[i].method = 0; 65 64 } 66 65 } 67 66 68 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 71 return ELIMIT; 73 74 int res = EEXISTS;75 event_t *event = events[e];76 77 spinlock_lock(&event->lock);78 if ( !event->answerbox) {79 event ->answerbox = answerbox;80 event ->method = method;81 event ->counter = 0;72 73 spinlock_lock(&events[evno].lock); 74 75 int res; 76 77 if (events[evno].answerbox == NULL) { 78 events[evno].answerbox = answerbox; 79 events[evno].method = method; 80 events[evno].counter = 0; 82 81 res = EOK; 83 } 84 spinlock_unlock(&event->lock); 85 82 } else 83 res = EEXISTS; 84 85 spinlock_unlock(&events[evno].lock); 86 86 87 return res; 87 88 } … … 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 98 bool res; 98 99 ASSERT(e < EVENT_END); 100 spinlock_lock(&events[e]->lock); 101 res = events[e]->answerbox != NULL; 102 spinlock_unlock(&events[e]->lock); 103 99 100 ASSERT(evno < EVENT_END); 101 102 spinlock_lock(&events[evno].lock); 103 res = events[evno].answerbox != NULL; 104 spinlock_unlock(&events[evno].lock); 105 104 106 return res; 105 107 } … … 108 110 void event_cleanup_answerbox(answerbox_t *answerbox) 109 111 { 110 int i;111 112 unsigned int i; 113 112 114 for (i = 0; i < EVENT_END; i++) { 113 spinlock_lock(&events[i] ->lock);114 if (events[i] ->answerbox == answerbox) {115 events[i] ->answerbox = NULL;116 events[i] ->counter = 0;117 events[i] ->method = 0;115 spinlock_lock(&events[i].lock); 116 if (events[i].answerbox == answerbox) { 117 events[i].answerbox = NULL; 118 events[i].counter = 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 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 127 unative_t a4, unative_t a5) 126 128 { 127 ASSERT(e < EVENT_END);128 event_t *event = events[e];129 spinlock_lock(&event ->lock);130 if (event ->answerbox) {129 ASSERT(evno < EVENT_END); 130 131 spinlock_lock(&events[evno].lock); 132 if (events[evno].answerbox != NULL) { 131 133 call_t *call = ipc_call_alloc(FRAME_ATOMIC); 132 134 if (call) { 133 135 call->flags |= IPC_CALL_NOTIF; 134 call->priv = ++event ->counter;135 IPC_SET_METHOD(call->data, event ->method);136 call->priv = ++events[evno].counter; 137 IPC_SET_METHOD(call->data, events[evno].method); 136 138 IPC_SET_ARG1(call->data, a1); 137 139 IPC_SET_ARG2(call->data, a2); … … 139 141 IPC_SET_ARG4(call->data, a4); 140 142 IPC_SET_ARG5(call->data, a5); 141 142 spinlock_lock(&event ->answerbox->irq_lock);143 list_append(&call->link, &event ->answerbox->irq_notifs);144 spinlock_unlock(&event ->answerbox->irq_lock);145 146 waitq_wakeup(&event ->answerbox->wq, WAKEUP_FIRST);143 144 spinlock_lock(&events[evno].answerbox->irq_lock); 145 list_append(&call->link, &events[evno].answerbox->irq_notifs); 146 spinlock_unlock(&events[evno].answerbox->irq_lock); 147 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
Note:
See TracChangeset
for help on using the changeset viewer.