source: mainline/kernel/generic/src/ipc/event.c@ c0f13d2

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since c0f13d2 was da1bafb, checked in by Martin Decky <martin@…>, 15 years ago

major code revision

  • replace spinlocks taken with interrupts disabled with irq_spinlocks
  • change spacing (not indendation) to be tab-size independent
  • use unsigned integer types where appropriate (especially bit flags)
  • visual separation
  • remove argument names in function prototypes
  • string changes
  • correct some formating directives
  • replace various cryptic single-character variables (t, a, m, c, b, etc.) with proper identifiers (thread, task, timeout, as, itm, itc, etc.)
  • unify some assembler constructs
  • unused page table levels are now optimized out in compile time
  • replace several ints (with boolean semantics) with bools
  • use specifically sized types instead of generic types where appropriate (size_t, uint32_t, btree_key_t)
  • improve comments
  • split asserts with conjuction into multiple independent asserts
  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * Copyright (c) 2009 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup generic
30 * @{
31 */
32/**
33 * @file
34 * @brief Kernel event notifications.
35 */
36
37#include <ipc/event.h>
38#include <ipc/event_types.h>
39#include <mm/slab.h>
40#include <typedefs.h>
41#include <synch/spinlock.h>
42#include <console/console.h>
43#include <memstr.h>
44#include <errno.h>
45#include <arch.h>
46
47/** The events array. */
48static event_t events[EVENT_END];
49
50/** Initialize kernel events. */
51void event_init(void)
52{
53 unsigned int i;
54
55 for (i = 0; i < EVENT_END; i++) {
56 spinlock_initialize(&events[i].lock, "event.lock");
57 events[i].answerbox = NULL;
58 events[i].counter = 0;
59 events[i].method = 0;
60 }
61}
62
63static int event_subscribe(event_type_t evno, unative_t method,
64 answerbox_t *answerbox)
65{
66 if (evno >= EVENT_END)
67 return ELIMIT;
68
69 spinlock_lock(&events[evno].lock);
70
71 int res;
72
73 if (events[evno].answerbox == NULL) {
74 events[evno].answerbox = answerbox;
75 events[evno].method = method;
76 events[evno].counter = 0;
77 res = EOK;
78 } else
79 res = EEXISTS;
80
81 spinlock_unlock(&events[evno].lock);
82
83 return res;
84}
85
86unative_t sys_event_subscribe(unative_t evno, unative_t method)
87{
88 return (unative_t) event_subscribe((event_type_t) evno, (unative_t)
89 method, &TASK->answerbox);
90}
91
92bool event_is_subscribed(event_type_t evno)
93{
94 bool res;
95
96 ASSERT(evno < EVENT_END);
97
98 spinlock_lock(&events[evno].lock);
99 res = events[evno].answerbox != NULL;
100 spinlock_unlock(&events[evno].lock);
101
102 return res;
103}
104
105
106void event_cleanup_answerbox(answerbox_t *answerbox)
107{
108 unsigned int i;
109
110 for (i = 0; i < EVENT_END; i++) {
111 spinlock_lock(&events[i].lock);
112 if (events[i].answerbox == answerbox) {
113 events[i].answerbox = NULL;
114 events[i].counter = 0;
115 events[i].method = 0;
116 }
117 spinlock_unlock(&events[i].lock);
118 }
119}
120
121void event_notify(event_type_t evno, unative_t a1, unative_t a2, unative_t a3,
122 unative_t a4, unative_t a5)
123{
124 ASSERT(evno < EVENT_END);
125
126 spinlock_lock(&events[evno].lock);
127 if (events[evno].answerbox != NULL) {
128 call_t *call = ipc_call_alloc(FRAME_ATOMIC);
129 if (call) {
130 call->flags |= IPC_CALL_NOTIF;
131 call->priv = ++events[evno].counter;
132 IPC_SET_METHOD(call->data, events[evno].method);
133 IPC_SET_ARG1(call->data, a1);
134 IPC_SET_ARG2(call->data, a2);
135 IPC_SET_ARG3(call->data, a3);
136 IPC_SET_ARG4(call->data, a4);
137 IPC_SET_ARG5(call->data, a5);
138
139 irq_spinlock_lock(&events[evno].answerbox->irq_lock, true);
140 list_append(&call->link, &events[evno].answerbox->irq_notifs);
141 irq_spinlock_unlock(&events[evno].answerbox->irq_lock, true);
142
143 waitq_wakeup(&events[evno].answerbox->wq, WAKEUP_FIRST);
144 }
145 }
146 spinlock_unlock(&events[evno].lock);
147}
148
149/** @}
150 */
Note: See TracBrowser for help on using the repository browser.