Explicitly include a boost "windows" folder even on linux
[supercollider.git] / include / lang / FIFOT.h
blobef31915d37b5676392df2464fffafdbe19ba115b
1 /*
2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 A Fifo for sending/receiving some type of object.
26 #ifndef _FIFOT_
27 #define _FIFOT_
29 #include "SCBase.h"
31 template <class T, int N> class FIFOT
33 public:
34 FIFOT()
35 : mMask(N-1), mReadHead(0), mWriteHead(0)
38 void MakeEmpty() { mReadHead = mWriteHead; }
39 bool IsEmpty() { return mReadHead == mWriteHead; }
40 int CanGet() {
41 int diff = mWriteHead - mReadHead;
42 return diff >= 0 ? diff : N - diff;
44 int CanPut() { return N-1-CanGet(); }
46 int NextPos(int inPos) { return (inPos + 1) & mMask; }
48 bool Put(const T& inItem)
50 long next = NextPos(mWriteHead);
51 if (next == mReadHead) return false; // fifo is full
52 mItems[next] = inItem;
53 mWriteHead = next;
54 return true;
57 bool Get(T& outItem) // get next and advance
59 if (IsEmpty()) return false;
60 long next = NextPos(mReadHead);
61 outItem = mItems[next];
62 mReadHead = next;
63 return true;
65 void DebugDump()
67 post("FIFO N %d mMask %d mReadHead %d mWriteHead%d\n",
68 N, mMask, mReadHead, mWriteHead);
71 private:
72 long mMask;
73 volatile long mReadHead, mWriteHead;// mReclaimHead;
74 T mItems[N];
77 #endif