2 * Copyright (C) 2017 Cisco Inc.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2,
6 * as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // @author Changxue Deng <chadeng@cisco.com>
24 MBlsq::MBlsq(void (*free_fn)(void *)) : FreeFunc(free_fn)
39 FreeFunc(node->data.data_ptr);
53 uint64_t MBlsq::Count() const
58 int MBlsq::AddToHead(void *ptr)
60 LSQ_Node *node = (LSQ_Node *) malloc(sizeof(*node));
62 return MBError::NO_MEMORY;
64 node->data.data_ptr = ptr;
71 return MBError::SUCCESS;
74 int MBlsq::AddIntToHead(int64_t value)
76 LSQ_Node *node = (LSQ_Node *) malloc(sizeof(*node));
78 return MBError::NO_MEMORY;
80 node->data.value = value;
87 return MBError::SUCCESS;
90 int MBlsq::AddIntToTail(int64_t value)
92 LSQ_Node *node = (LSQ_Node *) malloc(sizeof(*node));
94 return MBError::NO_MEMORY;
96 node->data.value = value;
110 return MBError::SUCCESS;
113 int MBlsq::AddToTail(void *ptr)
115 LSQ_Node *node = (LSQ_Node *) malloc(sizeof(*node));
117 return MBError::NO_MEMORY;
119 node->data.data_ptr = ptr;
132 return MBError::SUCCESS;
135 void* MBlsq::RemoveFromHead()
141 LSQ_Node *node = head;
142 data = head->data.data_ptr;
149 LSQ_Node *node = head;
150 data = head->data.data_ptr;
164 int64_t MBlsq::RemoveIntFromHead()
170 LSQ_Node *node = head;
171 value = head->data.value;
178 LSQ_Node *node = head;
179 value = head->data.value;