Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / msg / xio / XioInSeq.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7  * Portions Copyright (C) 2013 CohortFS, LLC
8  *
9  * This is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License version 2.1, as published by the Free Software
12  * Foundation.  See file COPYING.
13  *
14  */
15
16 #ifndef XIO_IN_SEQ_H
17 #define XIO_IN_SEQ_H
18
19 #include <boost/intrusive/list.hpp>
20 #include "msg/SimplePolicyMessenger.h"
21 extern "C" {
22 #include "libxio.h"
23 }
24
25 /* For inbound messages (Accelio-owned) ONLY, use the message's
26  * user_context as an SLIST */
27 class XioInSeq {
28 private:
29   int cnt;
30   int sz;
31   struct xio_msg* head;
32   struct xio_msg* tail;
33
34 public:
35   XioInSeq() : cnt(0), sz(0), head(NULL), tail(NULL) {}
36   XioInSeq(const XioInSeq& seq) {
37     cnt = seq.cnt;
38     sz = seq.sz;
39     head = seq.head;
40     tail = seq.tail;
41   }
42
43   int count() { return cnt; }
44
45   int size() { return sz; }
46
47   bool p() { return !!head; }
48
49   void set_count(int _cnt) { cnt = _cnt; }
50
51   void append(struct xio_msg* msg) {
52     msg->user_context = NULL;
53     if (!head) {
54       head = tail = msg;
55     } else {
56       tail->user_context = msg;
57       tail = msg;
58     }
59     ++sz;
60     --cnt;
61   }
62
63   struct xio_msg* begin() { return head; }
64
65   struct xio_msg* end() { return NULL; }
66
67   void next(struct xio_msg** msg) {
68     *msg = static_cast<struct xio_msg *>((*msg)->user_context);
69   }
70
71   struct xio_msg* dequeue() {
72     struct xio_msg* msgs = head;
73     clear();
74     return msgs;
75   }
76
77   void clear() {
78     head = tail = NULL;
79     cnt = 0;
80     sz = 0;
81   }
82 };
83
84 #endif /* XIO_IN_SEQ_H */