1 #include "inhibitor_mux.h"
2 #include <l4/sys/err.h>
5 Inhibitor_provider::Inhibitor_provider(Inhibitor_mux *mux)
8 _mux->_clients.add(this);
9 for (unsigned i = 0; i < L4VBUS_INHIBITOR_MAX; ++i)
11 _inhibitor_acquired[i] = false;
12 _inhibitor_reason[i][0] = 0;
16 Inhibitor_provider::~Inhibitor_provider()
18 _mux->_clients.remove(this);
20 for (unsigned i = 0; i < L4VBUS_INHIBITOR_MAX; ++i)
21 if (_inhibitor_acquired[i])
22 _mux->inhibitor_release(i);
26 Inhibitor_provider::inhibitor_acquire(l4_umword_t id, char const *reason)
28 if (id >= L4VBUS_INHIBITOR_MAX)
31 if (_inhibitor_acquired[id])
32 return; // already acquired, just ignore
34 unsigned long len = sizeof (_inhibitor_reason[id]);
35 strncpy(_inhibitor_reason[id], reason, len);
36 _inhibitor_reason[id][len - 1] = 0;
37 _inhibitor_acquired[id] = true;
38 _mux->inhibitor_acquire(id);
42 * \brief Release an inhibitor lock and unsubscribe the client from the
43 * corresponding signal.
45 * \param id Id of inhibitor lock to release.
48 Inhibitor_provider::inhibitor_release(l4_umword_t id)
50 if (id >= L4VBUS_INHIBITOR_MAX)
53 if (!_inhibitor_acquired[id])
54 return; // not acquired, just ignore
56 _inhibitor_acquired[id] = false;
57 _inhibitor_reason[id][0] = 0;
58 _mux->inhibitor_release(id);
62 * \brief Tell the mux that a client has taken a lock.
64 * Called by the Inhibitor_provider.
66 * \param id Id of lock that was taken.
69 Inhibitor_mux::inhibitor_acquire(l4_umword_t id)
71 if (id >= L4VBUS_INHIBITOR_MAX)
74 ++_inhibitors_acquired[id];
78 * \brief Tell the mux that a client released a lock.
80 * Called by the Inhibitor_provider. If the released lock was the last of its
81 * kind being held, all_inhibitors_free(type) will be called.
83 * \param id ID of the inhibitor_lock that was released.
86 Inhibitor_mux::inhibitor_release(l4_umword_t id)
88 if (id >= L4VBUS_INHIBITOR_MAX)
91 if (!--_inhibitors_acquired[id])
92 all_inhibitors_free(id);