2 * Copyright (c) 2013-2019, Intel Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
7 * * Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * * Neither the name of Intel Corporation nor the names of its contributors
13 * may be used to endorse or promote products derived from this software
14 * without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include "pt_event_queue.h"
34 static inline uint8_t pt_evq_inc(uint8_t idx)
42 static struct pt_event *pt_event_init(struct pt_event *event)
45 memset(event, 0, sizeof(*event));
50 void pt_evq_init(struct pt_event_queue *evq)
55 memset(evq, 0, sizeof(*evq));
58 struct pt_event *pt_evq_standalone(struct pt_event_queue *evq)
63 return pt_event_init(&evq->standalone);
66 struct pt_event *pt_evq_enqueue(struct pt_event_queue *evq,
67 enum pt_event_binding evb)
69 uint8_t begin, end, gap, idx;
77 begin = evq->begin[evb];
86 end = pt_evq_inc(idx);
87 gap = pt_evq_inc(end);
89 /* Leave a gap so we don't overwrite the last dequeued event. */
95 return pt_event_init(&evq->queue[evb][idx]);
98 struct pt_event *pt_evq_dequeue(struct pt_event_queue *evq,
99 enum pt_event_binding evb)
109 begin = evq->begin[evb];
112 if (evq_max <= begin)
121 evq->begin[evb] = pt_evq_inc(begin);
123 return &evq->queue[evb][begin];
126 int pt_evq_clear(struct pt_event_queue *evq, enum pt_event_binding evb)
129 return -pte_internal;
132 return -pte_internal;
140 int pt_evq_empty(const struct pt_event_queue *evq, enum pt_event_binding evb)
145 return -pte_internal;
148 return -pte_internal;
150 begin = evq->begin[evb];
153 if (evq_max <= begin)
154 return -pte_internal;
157 return -pte_internal;
162 int pt_evq_pending(const struct pt_event_queue *evq, enum pt_event_binding evb)
166 errcode = pt_evq_empty(evq, evb);
173 struct pt_event *pt_evq_find(struct pt_event_queue *evq,
174 enum pt_event_binding evb,
175 enum pt_event_type evt)
185 begin = evq->begin[evb];
188 if (evq_max <= begin)
194 for (; begin != end; begin = pt_evq_inc(begin)) {
197 ev = &evq->queue[evb][begin];