Commit b15deec1 authored by Felipe Sateler's avatar Felipe Sateler

Imported Upstream version 3.4-rev2

parents

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

Alberto de Campo <decampo att iem dott at>
Alex Norman <alex att x37v dot info>
Anders Vinjar <anders dott vinjar att notam dott uio dott no>
Andi Pieper <apieper att url dott de>
Axel Balley <axel dott lists att gmail dott com>
Benjamin Golinvaux <Benjamin dott Golinvaux att euresys dott com>
Blackrain <blackrain dott sc att gmail dott com>
Charles Picasso <thelych att gmail dott com>
Chris Sattinger (Crucial Felix) <felix att crucial-systems dott com>
Christian A. Hresko <christian dott hresko att verizon dott net>
Christophe Costigan
Christopher Frauenberger <frauenberger att iem dott at>
Dan Stowell <danstowell att users dott sourceforge dott net>
Dave Watson <dave att elephantride dott org>
Fredrik Olofsson <f att fredrikolofsson dott com>
Gerard Roma <0001 att ooo000ooo dott org>
Hanns Holger Rutz <contact at sciss dott de>
James Harkins <jamshark70 att gmail dott com>
James McCartney <asynth att gmail dott com>
Jan Trutzschler <sc3 att sampleAndHold dott org>
John Glover <glover dott john att gmail dott com>
Josh Davison
Joshua Parmenter <josh att realizedsound dott net>
Jost Muxfeldt <jost dott muxfeldt att glyph dott de>
Julian Rohrhuber <rohrhuber att uni-hamburg dott de>
Kasper Souren <Kasper dott Souren att ircam dott fr>
Marije Baalman <nescivi att gmail dott com>
Mario Lang <mlang att delysid dott org>
Mark Polishook <polishook att optonline dott net>
Maurizio Umberto Puxeddu <umbpux att tin dott it>
Mike Whyte <matrix6k att somahq dott com>
Newton Armstrong <newton att silvertone dott princeton dott edu>
Nick Collins <N dott Collins att sussex dott ac dott uk>
Patrick Beard <pcbeard att mac dott com>
Rohan Drape <rd att slavepianos dott org>
Ron Kuivila <rkuivila att wesleyan dott edu>
Ross Bencina <rossb att audiomulch dott com>
Ryan Brown <ryan att wabdo dott com>
Scott Wilson <i att scottwilson dott ca>
Stefan Kersten <sk att k-hornz dott de>
Thor Magnusson <T dott Magnusson att sussex dott ac dott uk>
Till Bovermann <lfsaw att lfsaw dott de>
Tim Blechmann <tim att klingt dott org>
Tim Walters <walters att doubtfulpalace dott com>
and others.
This diff is collapsed.
This diff is collapsed.
3.4
classvar scVersionMajor=3, scVersionMinor=4, scVersionPostfix="";
/*
SuperCollider real time audio synthesis system
Copyright (c) 2002 James McCartney. All rights reserved.
http://www.audiosynth.com
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/*
This is based on Doug Lea's allocator but rewritten so I can read and understand it...
also features of free all-at-once pools are added.
Now uses 16 byte alignment, which does increase the minimum allocation size to 32 bytes
including the overhead.
Improved bit block scanning by using a count leading zeroes instruction.
*/
#ifndef _AllocPool_
#define _AllocPool_
#include "SC_List.h"
#include "clz.h"
#include <stdlib.h>
const int kNumAllocBins = 128;
const int kNumSmallBins = 64;
const int kMaxSmallBin = kNumSmallBins - 1;
const int kBinWidth = 8;
const int kMaxSmallBinSize = kNumSmallBins * kBinWidth;
const int kBinBlockWidth = 4;
const int kBinBlockMask = kBinBlockWidth - 1;
const size_t kAlign = 16;
const size_t kAlignMask = kAlign - 1;
const size_t kChunkFree = 0;
const size_t kChunkInUse = 1;
const size_t kSizeBits = ~kChunkInUse;
class AllocChunk;
class AllocPool;
typedef AllocChunk *AllocChunkPtr;
typedef Link<AllocChunk> AllocBin;
typedef AllocBin* AllocBinPtr;
class AllocChunk : public Link<AllocChunk>
{
friend class AllocPool;
size_t Size()
{ return mSize & kSizeBits; }
size_t PrevSize()
{ return mPrevSize & kSizeBits; }
AllocChunkPtr ChunkAtOffset(long inSize)
{ return AllocChunkPtr((char*)this + inSize); }
AllocChunkPtr NextChunk()
{ return ChunkAtOffset(Size()); }
AllocChunkPtr PrevChunk()
{ return ChunkAtOffset(-(long)PrevSize()); }
bool InUse()
{ return (bool)(mSize & kChunkInUse); }
bool PrevInUse()
{ return (bool)(mPrevSize & kChunkInUse); }
void SetSizeFree(size_t inSize)
{ mSize = ChunkAtOffset(inSize)->mPrevSize = inSize; }
void SetSizeInUse(size_t inSize)
{ mSize = ChunkAtOffset(inSize)->mPrevSize = inSize | kChunkInUse; }
void SetNeighborsInUse(size_t inOffset)
{ mPrevSize = ChunkAtOffset(inOffset)->mSize = kChunkInUse; }
bool IsArea()
{ return mPrevSize == kChunkInUse && NextChunk()->mSize == kChunkInUse; }
void* ToPtr()
{ return (void*)((char*)this + sizeof(AllocChunk)); }
size_t mPrevSize;
size_t mSize;
};
class AllocArea;
typedef AllocArea* AllocAreaPtr;
class AllocAreaHdr /* for size calculations */
{
protected:
friend class AllocPool;
AllocAreaPtr mPrev, mNext;
size_t mSize;
void *mUnalignedPointerToThis;
};
class AllocArea : public AllocAreaHdr
{
public:
void SanityCheck();
private:
friend class AllocPool;
AllocChunk mChunk;
};
const size_t kMinAllocSize = 2 * kAlign;
// FIXME: add kAlign to overhead? <sk>
const size_t kAreaOverhead = sizeof(AllocAreaHdr) + 2 * sizeof(AllocChunk);
typedef void* (*NewAreaFunc)(size_t size);
typedef void (*FreeAreaFunc)(void *);
class AllocPool
{
public:
AllocPool(NewAreaFunc allocArea, FreeAreaFunc freeArea,
size_t areaInitSize, size_t areaMoreSize);
~AllocPool();
void Reinit();
void *Alloc(size_t inBytes);
void *Realloc(void* inPtr, size_t inBytes);
void Free(void* inPtr);
void FreeAll();
void FreeAllInternal();
// debugging
size_t TotalFree();
size_t LargestFreeChunk();
void DoCheckPool();
void DoCheckInUseChunk(AllocChunkPtr p);
static AllocChunkPtr MemToChunk(void *inPtr)
{ return (AllocChunkPtr)((char*)(inPtr) - sizeof(AllocChunk)); }
private:
void InitAlloc();
void InitBins();
AllocAreaPtr NewArea(size_t inAreaSize);
void FreeArea(AllocChunkPtr chunk);
// debugging
void DoCheckArea(AllocAreaPtr area);
void DoCheckBin(AllocChunkPtr bin, long idx);
void DoCheckChunk(AllocChunkPtr p);
void DoCheckFreeChunk(AllocChunkPtr p);
void DoCheckAllocedChunk(AllocChunkPtr p, size_t s);
void DoGarbageFill(AllocChunkPtr p);
void DoGarbageFill(AllocChunkPtr p, long size);
// inlines
static size_t RequestToSize(size_t inReqSize)
{
size_t sizePlusOverhead = inReqSize + sizeof(AllocChunk);
if (sizePlusOverhead <= kMinAllocSize) return kMinAllocSize;
else return (sizePlusOverhead + kAlignMask) & ~kAlignMask;
}
static int SmallBinIndex(size_t inSize)
{ return inSize >> 4; }
static int BinIndex2(size_t inSize)
{
return
((inSize < 1024) ? (inSize>>4):
(inSize < 2048) ? 56 + (inSize>>7):
(inSize < 4096) ? 64 + (inSize>>8):
(inSize < 8192) ? 72 + (inSize>>9):
(inSize < 16384) ? 80 + (inSize>>10):
(inSize < 32768) ? 88 + (inSize>>11):
(inSize < 65536) ? 96 + (inSize>>12):
(inSize < 131072) ? 104 + (inSize>>13):
(inSize < 262144) ? 112 + (inSize>>14):127);
}