blob: 2fd996f16c9c89f1ce7fb9301905ea7438ff7bb9 [file] [log] [blame]
Ernesto Posse8a4f2962015-05-12 13:28:46 -04001// umlrtpool.cc
2
3/*******************************************************************************
4 * Copyright (c) 2014-2015 Zeligsoft (2009) Limited and others.
5 * All rights reserved. This program and the accompanying materials
6 * are made available under the terms of the Eclipse Public License v1.0
7 * which accompanies this distribution, and is available at
8 * http://www.eclipse.org/legal/epl-v10.html
9 *******************************************************************************/
10
11#include <stdlib.h>
12#include "basefatal.hh"
13#include "basedebug.hh"
14#include "umlrtguard.hh"
15#include "umlrtpool.hh"
16#include "umlrtqueueelement.hh"
17#include "umlrtuserconfig.hh"
18
19// See umlrtqueue.hh for documentation.
20
21// Create an empty queue.
22UMLRTPool::UMLRTPool(size_t incrementSize) :
23 head(0), increment(incrementSize), qid(0)
24{
25}
26
27UMLRTPool::~UMLRTPool()
28{
29}
30
31// Remove the first element on the pool.
32// Grow the list if it is empty
33const UMLRTQueueElement * UMLRTPool::get()
34{
35 UMLRTGuard g(mutex);
36
37 if (head == NULL)
38 {
39 grow();
40 }
41 const UMLRTQueueElement * element = head;
42 head = element->next;
43 return element;
44}
45
46// Add element back to pool (at front).
47void UMLRTPool::put(const UMLRTQueueElement * element)
48{
49 UMLRTGuard g(mutex);
50 if (element)
51 {
52 element->next = head;
53 head = element;
54 }
55}