Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXLFQueue.h
1 /********************************************************************************
2 * *
3 * L o c k - F r e e Q u e u e *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2012,2022 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXLFQUEUE_H
22 #define FXLFQUEUE_H
23 
24 namespace FX {
25 
26 
28 class FXAPI FXLFQueue {
29 private:
30  FXPtrList items; // Item buffer
31  volatile FXuint whead; // Head write pointer
32  volatile FXuint wtail; // Tail write pointer
33  volatile FXuint rhead; // Head read pointer
34  volatile FXuint rtail; // Tail read pointer
35 private:
36  FXLFQueue(const FXLFQueue&);
37  FXLFQueue &operator=(const FXLFQueue&);
38 public:
39 
41  FXLFQueue();
42 
44  FXLFQueue(FXuint sz);
45 
47  FXbool setSize(FXuint sz);
48 
50  FXuint getSize() const { return (FXuint)items.no(); }
51 
53  FXuint getUsed() const;
54 
56  FXuint getFree() const;
57 
59  FXbool isFull() const;
60 
62  FXbool isEmpty() const;
63 
65  FXbool push(FXptr ptr);
66 
68  FXbool pop(FXptr& ptr);
69 
71  ~FXLFQueue();
72  };
73 
74 
76 template <typename TYPE>
77 class FXLFQueueOf : public FXLFQueue {
78 public:
79  FXLFQueueOf(){}
80  FXLFQueueOf(FXuint sz):FXLFQueue(sz){}
81  FXbool push(TYPE* ptr){ return FXLFQueue::push((FXptr)ptr); }
82  FXbool pop(TYPE*& ptr){ return FXLFQueue::pop((FXptr&)ptr); }
83  };
84 
85 }
86 
87 #endif
Lock-free queue of void pointers.
Definition: FXLFQueue.h:28
FXuint getSize() const
Return size.
Definition: FXLFQueue.h:50
Definition: FX4Splitter.h:28
FXbool pop(FXptr &ptr)
Remove item from queue, return true if success.
FXival no() const
Return number of objects.
Definition: FXPtrList.h:55
FXbool push(FXptr ptr)
Add item to queue, return true if success.
Lock-free queue of pointers to TYPE.
Definition: FXLFQueue.h:77
List of void pointers.
Definition: FXPtrList.h:28
FXLFQueue()
Create initially empty queue.

Copyright © 1997-2022 Jeroen van der Zijp