static void allocateAtomBlock(int idx) { PL_LOCK(L_MISC); if ( !GD->atoms.array.blocks[idx] ) { size_t bs = (size_t)1<<idx; Atom newblock; if ( !(newblock=PL_malloc_uncollectable(bs*sizeof(struct atom))) ) outOfCore(); memset(newblock, 0, bs*sizeof(struct atom)); GD->atoms.array.blocks[idx] = newblock-bs; } PL_UNLOCK(L_MISC); }
static void allocateFunctorBlock(int idx) { PL_LOCK(L_MISC); if ( !GD->functors.array.blocks[idx] ) { size_t bs = (size_t)1<<idx; FunctorDef *newblock; if ( !(newblock=PL_malloc_uncollectable(bs*sizeof(FunctorDef))) ) outOfCore(); memset(newblock, 0, bs*sizeof(FunctorDef)); GD->functors.array.blocks[idx] = newblock-bs; } PL_UNLOCK(L_MISC); }
static void putFunctorArray(size_t where, FunctorDef fd) { int idx = MSB(where); assert(where >= 0); if ( !GD->functors.array.blocks[idx] ) { PL_LOCK(L_MISC); if ( !GD->functors.array.blocks[idx] ) { size_t bs = (size_t)1<<idx; FunctorDef *newblock = PL_malloc_uncollectable(bs*sizeof(FunctorDef)); GD->functors.array.blocks[idx] = newblock-bs; } PL_UNLOCK(L_MISC); } GD->functors.array.blocks[idx][where] = fd; }
static void putSourceFileArray(size_t where, SourceFile sf) { int idx = MSB(where); if ( !GD->files.array.blocks[idx] ) { PL_LOCK(L_MISC); if ( !GD->files.array.blocks[idx] ) { size_t bs = (size_t)1<<idx; SourceFile *newblock; if ( !(newblock=PL_malloc_uncollectable(bs*sizeof(SourceFile))) ) outOfCore(); memset(newblock, 0, bs*sizeof(SourceFile)); GD->files.array.blocks[idx] = newblock-bs; } PL_UNLOCK(L_MISC); } GD->files.array.blocks[idx][where] = sf; }
static void putAtomArray(size_t where, Atom a) { int idx = MSB(where); assert(where >= 0); if ( !GD->atoms.array.blocks[idx] ) { PL_LOCK(L_MISC); if ( !GD->atoms.array.blocks[idx] ) { size_t bs = (size_t)1<<idx; Atom *newblock; if ( !(newblock=PL_malloc_uncollectable(bs*sizeof(Atom))) ) outOfCore(); memset(newblock, 0, bs*sizeof(Atom)); GD->atoms.array.blocks[idx] = newblock-bs; } PL_UNLOCK(L_MISC); } GD->atoms.array.blocks[idx][where] = a; }