1 /** @addtogroup MCD_MCDIMPL_DAEMON_DEV
2 * @{
3 * @file
4 *
5 *
6 * <!-- Copyright Giesecke & Devrient GmbH 2009 - 2012 -->
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote
17 * products derived from this software without specific prior
18 * written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
21 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
26 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 #include "NotificationQueue.h"
33 #include <stddef.h>
34
35 #include "log.h"
36
37 //------------------------------------------------------------------------------
NotificationQueue(notificationQueue_t * i,notificationQueue_t * o,uint32_t size)38 NotificationQueue::NotificationQueue(
39 notificationQueue_t *i,
40 notificationQueue_t *o,
41 uint32_t size
42 ) : in(i), out(o)
43 {
44 in->hdr.queueSize = size;
45 out->hdr.queueSize = size;
46 }
47
48
49 //------------------------------------------------------------------------------
putNotification(notification_t * notification)50 void NotificationQueue::putNotification(
51 notification_t *notification
52 )
53 {
54 mutex.lock();
55 if ((out->hdr.writeCnt - out->hdr.readCnt) < out->hdr.queueSize) {
56 out->notification[out->hdr.writeCnt & (out->hdr.queueSize - 1)]
57 = *notification;
58 out->hdr.writeCnt++;
59 }
60 mutex.unlock();
61 }
62
63
64 //------------------------------------------------------------------------------
getNotification(void)65 notification_t *NotificationQueue::getNotification(
66 void
67 )
68 {
69 notification_t *ret = NULL;
70 mutex.lock();
71 if ((in->hdr.writeCnt - in->hdr.readCnt) > 0) {
72 ret = &(in->notification[in->hdr.readCnt & (in->hdr.queueSize - 1)]);
73 in->hdr.readCnt++;
74 }
75 mutex.unlock();
76 return ret;
77 }
78
79 /** @} */
80