/usr/include/sc/util/group/pool.h is in libsc-dev 2.3.1-18build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | //
// pool.h
//
// Copyright (C) 1996 Limit Point Systems, Inc.
//
// Author: Curtis Janssen <cljanss@limitpt.com>
// Maintainer: LPS
//
// This file is part of the SC Toolkit.
//
// The SC Toolkit is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published by
// the Free Software Foundation; either version 2, or (at your option)
// any later version.
//
// The SC Toolkit 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 Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
//
// The U.S. Government is granted a limited license as per AL 91-7.
//
#ifdef __GNUC__
#pragma interface
#endif
#ifndef _util_group_pool_h
#define _util_group_pool_h
#include <stdlib.h>
#include <new>
#include <iostream>
#include <util/misc/exenv.h>
#undef DEBUG_POOL
namespace sc {
const int pool_data_alignment_bit = 3;
//const int pool_data_alignment_bit = 14;
const size_t pool_data_alignment = 1<<pool_data_alignment_bit;
inline size_t
align_pool_data(size_t size)
{
return (size + pool_data_alignment - 1)
& (~ (pool_data_alignment - 1));
}
inline void*
align_pool_data(void* ptr)
{
return (void*)( (unsigned long) ((char*)ptr + pool_data_alignment - 1)
& (~ (pool_data_alignment - 1)));
}
inline size_t
align_pool_data_downward(size_t size)
{
return size & (~ (pool_data_alignment - 1));
}
inline void*
align_pool_data_downward(void* ptr)
{
return (void*) ( (unsigned long) ptr & (~ (pool_data_alignment - 1)));
}
// ////////////////////////////////////////////////////////////////////////////
class PoolData;
struct FreeData {
PoolData* next_free_;
PoolData* prev_free_;
};
// ////////////////////////////////////////////////////////////////////////////
struct UsedData {
unsigned int flags;
unsigned int held_:16;
int priority_:15;
unsigned int fixed_:1;
};
// ////////////////////////////////////////////////////////////////////////////
class PoolData {
public:
enum {magic = 0x1f1d1e1c};
int magic_;
size_t size_;
unsigned int free_:1;
unsigned int flags_:15;
private:
PoolData* next_;
PoolData* prev_;
public:
union {
FreeData f;
UsedData u;
};
// Allocates a chunk of free memory, only initializing the size.
PoolData(size_t size);
PoolData* next();
PoolData* prev();
void next(PoolData*);
void prev(PoolData*);
void prev_next(PoolData*,PoolData*);
PoolData* next_free();
PoolData* prev_free();
void next_free(PoolData*);
void prev_free(PoolData*);
void prev_next_free(PoolData*,PoolData*);
void set_magic(int = magic);
// This new can only be called with aligned memory.
//void* operator new(size_t size, void* placement);
void* data();
void check(void*lower=(void*)0x0,void*upper=(void*)0x7fffffffL);
};
const int PoolData_aligned_size = (sizeof(PoolData) + pool_data_alignment - 1)
& (~ (pool_data_alignment - 1));
inline void* PoolData::data()
{
return (void*)(((char*)this) + PoolData_aligned_size);
}
inline PoolData*
PoolData::next()
{
return next_;
}
inline PoolData*
PoolData::prev()
{
return prev_;
}
inline void
PoolData::next(PoolData*p)
{
next_ = p;
#ifdef DEBUG_POOL
if (next_ && prev_ && (next_ < prev_)) {
ExEnv::errn() << "PoolData::next(PoolData*): next < prev" << endl;
abort();
}
#endif
}
inline void
PoolData::prev(PoolData*p)
{
prev_ = p;
#ifdef DEBUG_POOL
if (next_ && prev_ && (next_ < prev_)) {
ExEnv::errn() << "PoolData::prev(PoolData*): next < prev" << endl;
abort();
}
#endif
}
inline void
PoolData::prev_next(PoolData*p,PoolData*n)
{
prev_ = p;
next_ = n;
#ifdef DEBUG_POOL
if (next_ && prev_ && (next_ < prev_)) {
ExEnv::errn() << "PoolData::prev_next: next < prev" << endl;
abort();
}
#endif
}
// ////
inline PoolData*
PoolData::next_free()
{
#ifdef DEBUG_POOL
if (!free_) {
ExEnv::errn() << "PoolData::next_free(): datum is not free" << endl;
abort();
}
#endif
return f.next_free_;
}
inline PoolData*
PoolData::prev_free()
{
#ifdef DEBUG_POOL
if (!free_) {
ExEnv::errn() << "PoolData::prev_free(): datum is not free" << endl;
abort();
}
#endif
return f.prev_free_;
}
inline void
PoolData::next_free(PoolData*p)
{
#ifdef DEBUG_POOL
if (!free_) {
ExEnv::errn() << "PoolData::next_free(PoolData*): datum is not free" << endl;
abort();
}
#endif
f.next_free_ = p;
}
inline void
PoolData::prev_free(PoolData*p)
{
#ifdef DEBUG_POOL
if (!free_) {
ExEnv::errn() << "PoolData::prev_free(PoolData*): datum is not free" << endl;
abort();
}
#endif
f.prev_free_ = p;
}
inline void
PoolData::prev_next_free(PoolData*p,PoolData*n)
{
#ifdef DEBUG_POOL
if (!free_) {
ExEnv::errn() << "PoolData::prev_next_free: datum is not free" << endl;
abort();
}
#endif
f.prev_free_ = p;
f.next_free_ = n;
}
inline
PoolData::PoolData(size_t size):
magic_(magic),
size_(size-PoolData_aligned_size)
{
}
inline void
PoolData::set_magic(int magic_a)
{
magic_ = magic_a;
}
// ////////////////////////////////////////////////////////////////////////////
class Pool {
protected:
enum { freelist_size = sizeof(size_t)*8 };
PoolData* freelist_[freelist_size];
size_t size_;
PoolData* firstdatum_;
PoolData* voidptr_to_pd(void*d);
int freelist_find_slot(size_t);
void freelist_add(PoolData*);
void freelist_del(PoolData*);
public:
Pool(size_t);
~Pool();
// void* operator new(size_t size, void* placement) { return placement; }
// Handle& allocate_handle(size_t size, int priority = 0);
// void release(Handle&);
size_t size() { return size_; }
void* allocate(size_t size);
void release(void*d);
double* allocate_double(size_t n);
void release(double*d);
int* allocate_int(size_t n);
void release(int*d);
void print(std::ostream&o=ExEnv::out0());
void check();
};
inline PoolData*
Pool::voidptr_to_pd(void*d)
{
return (PoolData*)((char*)d - PoolData_aligned_size);
}
inline double*
Pool::allocate_double(size_t n)
{
return (double*) allocate(n*sizeof(double));
}
inline void
Pool::release(double*d)
{
release((void*)d);
}
inline int*
Pool::allocate_int(size_t n)
{
return (int*) allocate(n*sizeof(int));
}
inline void
Pool::release(int*d)
{
release((void*)d);
}
}
#endif
// Local Variables:
// mode: c++
// c-file-style: "CLJ"
// End:
|