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

FXSemaQueue.h
1 /********************************************************************************
2 * *
3 * S e m a p h o r e Q u e u e *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2006,2017 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 FXSEMAQUEUE_H
22 #define FXSEMAQUEUE_H
23 
24 namespace FX {
25 
26 
28 class FXAPI FXSemaQueue {
29 private:
30  FXPtrQueue list; // Queue
31  FXSemaphore free; // Free cells
32  FXSemaphore used; // Used cells
33 private:
34  FXSemaQueue(const FXSemaQueue&);
35  FXSemaQueue &operator=(const FXSemaQueue&);
36 public:
37 
39  FXSemaQueue(FXuint sz=32);
40 
42  FXbool trypush(FXptr obj);
43 
45  FXbool push(FXptr ptr);
46 
48  FXbool trypop(FXptr& obj);
49 
51  FXbool pop(FXptr& ptr);
52 
54  FXbool pop();
55 
57  ~FXSemaQueue();
58  };
59 
60 
61 // Specialize to pointers to TYPE
62 template<typename TYPE>
63 class FXSemaQueueOf : public FXSemaQueue {
64 public:
65  FXSemaQueueOf(){}
66  FXSemaQueueOf(FXuint sz):FXSemaQueue(sz){}
67  FXbool trypush(TYPE* obj){ return FXSemaQueue::trypush((FXptr)obj); }
68  FXbool push(TYPE* obj){ return FXSemaQueue::push((FXptr)obj); }
69  FXbool trypop(TYPE*& obj){ return FXSemaQueue::trypop((FXptr&)obj); }
70  FXbool pop(TYPE*& obj){ return FXSemaQueue::pop((FXptr&)obj); }
71  };
72 
73 
74 }
75 
76 #endif

Copyright © 1997-2016 Jeroen van der Zijp