Motr  M0
msg_queue.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2016-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 
30 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_HA
31 #include "lib/trace.h"
32 
33 #include "ha/msg_queue.h"
34 
35 #include "lib/memory.h" /* M0_ALLOC_PTR */
36 
37 M0_TL_DESCR_DEFINE(ha_mq, "m0_ha_msg_queue::mq_queue", static,
38  struct m0_ha_msg_qitem, hmq_link, hmq_magic,
40 M0_TL_DEFINE(ha_mq, static, struct m0_ha_msg_qitem);
41 
42 M0_INTERNAL void m0_ha_msg_queue_init(struct m0_ha_msg_queue *mq,
43  struct m0_ha_msg_queue_cfg *cfg)
44 {
45  ha_mq_tlist_init(&mq->mq_queue);
46 }
47 
48 M0_INTERNAL void m0_ha_msg_queue_fini(struct m0_ha_msg_queue *mq)
49 {
50  ha_mq_tlist_fini(&mq->mq_queue);
51 }
52 
53 M0_INTERNAL struct m0_ha_msg_qitem *
55 {
56  struct m0_ha_msg_qitem *qitem;
57 
58  M0_ALLOC_PTR(qitem);
59  return qitem;
60 }
61 
62 M0_INTERNAL void m0_ha_msg_queue_free(struct m0_ha_msg_queue *mq,
63  struct m0_ha_msg_qitem *qitem)
64 {
65  m0_free(qitem);
66 }
67 
68 M0_INTERNAL void m0_ha_msg_queue_enqueue(struct m0_ha_msg_queue *mq,
69  struct m0_ha_msg_qitem *qitem)
70 {
71  ha_mq_tlink_init_at_tail(qitem, &mq->mq_queue);
72 }
73 
74 M0_INTERNAL struct m0_ha_msg_qitem *
76 {
77  struct m0_ha_msg_qitem *qitem;
78 
79  qitem = ha_mq_tlist_pop(&mq->mq_queue);
80  if (qitem != NULL)
81  ha_mq_tlink_fini(qitem);
82  return qitem;
83 }
84 
85 M0_INTERNAL void m0_ha_msg_queue_push_front(struct m0_ha_msg_queue *mq,
86  struct m0_ha_msg_qitem *qitem)
87 {
88  ha_mq_tlink_init_at(qitem, &mq->mq_queue);
89 }
90 
91 M0_INTERNAL bool m0_ha_msg_queue_is_empty(struct m0_ha_msg_queue *mq)
92 {
93  return ha_mq_tlist_is_empty(&mq->mq_queue);
94 }
95 
96 M0_INTERNAL struct m0_ha_msg_qitem *
98  uint64_t tag)
99 {
100  return m0_tl_find(ha_mq, qitem, &mq->mq_queue,
101  m0_ha_msg_tag(&qitem->hmq_msg) == tag);
102 }
103 
104 M0_INTERNAL struct m0_ha_msg_qitem *
106  const struct m0_ha_msg_qitem *cur)
107 {
108  M0_PRE(cur != NULL);
109  return ha_mq_tlist_next(&mq->mq_queue, cur);
110 }
111 
112 M0_INTERNAL struct m0_ha_msg_qitem *
114  const struct m0_ha_msg_qitem *cur)
115 {
116  M0_PRE(cur != NULL);
117  return ha_mq_tlist_prev(&mq->mq_queue, cur);
118 }
119 
120 #undef M0_TRACE_SUBSYSTEM
121 
124 /*
125  * Local variables:
126  * c-indentation-style: "K&R"
127  * c-basic-offset: 8
128  * tab-width: 8
129  * fill-column: 80
130  * scroll-step: 1
131  * End:
132  */
133 /*
134  * vim: tabstop=8 shiftwidth=8 noexpandtab textwidth=80 nowrap
135  */
#define M0_PRE(cond)
#define NULL
Definition: misc.h:38
static struct buffer * cur(struct m0_addb2_mach *mach, m0_bcount_t space)
Definition: addb2.c:791
static uint64_t tag(uint8_t code, uint64_t id)
Definition: addb2.c:1047
M0_INTERNAL struct m0_ha_msg_qitem * m0_ha_msg_queue_dequeue(struct m0_ha_msg_queue *mq)
Definition: msg_queue.c:75
struct m0_tl mq_queue
Definition: msg_queue.h:63
M0_INTERNAL void m0_ha_msg_queue_enqueue(struct m0_ha_msg_queue *mq, struct m0_ha_msg_qitem *qitem)
Definition: msg_queue.c:68
M0_TL_DESCR_DEFINE(ha_mq, "m0_ha_msg_queue::mq_queue", static, struct m0_ha_msg_qitem, hmq_link, hmq_magic, M0_HA_MSG_QITEM_MAGIC, M0_HA_MSG_QUEUE_HEAD_MAGIC)
M0_INTERNAL struct m0_ha_msg_qitem * m0_ha_msg_queue_find(struct m0_ha_msg_queue *mq, uint64_t tag)
Definition: msg_queue.c:97
M0_INTERNAL void m0_ha_msg_queue_fini(struct m0_ha_msg_queue *mq)
Definition: msg_queue.c:48
M0_INTERNAL void m0_ha_msg_queue_free(struct m0_ha_msg_queue *mq, struct m0_ha_msg_qitem *qitem)
Definition: msg_queue.c:62
M0_INTERNAL struct m0_ha_msg_qitem * m0_ha_msg_queue_alloc(struct m0_ha_msg_queue *mq)
Definition: msg_queue.c:54
M0_INTERNAL uint64_t m0_ha_msg_tag(const struct m0_ha_msg *msg)
Definition: msg.c:36
M0_INTERNAL bool m0_ha_msg_queue_is_empty(struct m0_ha_msg_queue *mq)
Definition: msg_queue.c:91
M0_TL_DEFINE(ha_mq, static, struct m0_ha_msg_qitem)
M0_INTERNAL struct m0_ha_msg_qitem * m0_ha_msg_queue_next(struct m0_ha_msg_queue *mq, const struct m0_ha_msg_qitem *cur)
Definition: msg_queue.c:105
#define M0_ALLOC_PTR(ptr)
Definition: memory.h:86
M0_INTERNAL struct m0_ha_msg_qitem * m0_ha_msg_queue_prev(struct m0_ha_msg_queue *mq, const struct m0_ha_msg_qitem *cur)
Definition: msg_queue.c:113
#define m0_tl_find(name, var, head,...)
Definition: tlist.h:757
void m0_free(void *data)
Definition: memory.c:146
M0_INTERNAL void m0_ha_msg_queue_init(struct m0_ha_msg_queue *mq, struct m0_ha_msg_queue_cfg *cfg)
Definition: msg_queue.c:42
M0_INTERNAL void m0_ha_msg_queue_push_front(struct m0_ha_msg_queue *mq, struct m0_ha_msg_qitem *qitem)
Definition: msg_queue.c:85