• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements.  See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership.  The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License.  You may obtain a copy of the License at
9  *
10  *  http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied.  See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 #include "ble_hs_priv.h"
21 
ble_mqueue_init(struct ble_mqueue * mq,ble_npl_event_fn * ev_fn,void * ev_arg)22 int ble_mqueue_init(struct ble_mqueue *mq, ble_npl_event_fn *ev_fn, void *ev_arg)
23 {
24     STAILQ_INIT(&mq->head);
25     ble_npl_event_init(&mq->ev, ev_fn, ev_arg);
26     return (0);
27 }
28 
ble_mqueue_get(struct ble_mqueue * mq)29 struct os_mbuf *ble_mqueue_get(struct ble_mqueue *mq)
30 {
31     struct os_mbuf_pkthdr *mp;
32     struct os_mbuf *om;
33     os_sr_t sr;
34     OS_ENTER_CRITICAL(sr);
35     mp = STAILQ_FIRST(&mq->head);
36     if (mp) {
37         STAILQ_REMOVE_HEAD(&mq->head, omp_next);
38     }
39 
40     OS_EXIT_CRITICAL(sr);
41 
42     if (mp) {
43         om = OS_MBUF_PKTHDR_TO_MBUF(mp);
44     } else {
45         om = NULL;
46     }
47 
48     return (om);
49 }
50 
ble_mqueue_put(struct ble_mqueue * mq,struct ble_npl_eventq * evq,struct os_mbuf * om)51 int ble_mqueue_put(struct ble_mqueue *mq, struct ble_npl_eventq *evq, struct os_mbuf *om)
52 {
53     struct os_mbuf_pkthdr *mp;
54     os_sr_t sr;
55     int rc;
56 
57     /* Can only place the head of a chained mbuf on the queue. */
58     if (!OS_MBUF_IS_PKTHDR(om)) {
59         rc = OS_EINVAL;
60         goto err;
61     }
62 
63     mp = OS_MBUF_PKTHDR(om);
64     OS_ENTER_CRITICAL(sr);
65     STAILQ_INSERT_TAIL(&mq->head, mp, omp_next);
66     OS_EXIT_CRITICAL(sr);
67 
68     /* Only post an event to the queue if its specified */
69     if (evq) {
70         ble_npl_eventq_put(evq, &mq->ev);
71     }
72 
73     return (0);
74 err:
75     return (rc);
76 }