YAP 7.1.0
YapArenas.h
1/**********************************************************************
2 * *
3 * YAP Prolog *
4 * *
5 * Yap Prolog was developed at NCCUP - Universidade do Porto *
6 * *
7 * Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
8 * *
9 **************************************************************************
10 * *
11 * File: YapArenas.h * Last rev: 4/03/88
12 *
13 * mods:
14 * comments: Memory allocation for global variables *
15 * *
16 *************************************************************************/
17
18#ifndef YAPARENAS_H
19#define YAPARENAS_H 1
20
21#include "terms.h"
22
23extern Term Yap_MkArena(CELL *ptr, CELL *max);
24extern bool Yap_ArenaExpand(size_t sz, CELL *arenap);
25
26#define MIN_ARENA_SIZE (1024L)
27
28#define MAX_ARENA_SIZE (2048 * MIN_ARENA_SIZE)
29
30#define Global_MkIntegerTerm(I) MkIntegerTerm(I)
31
32static size_t big2arena_szW(CELL *arena_base) {
33 return arena_base[2] + 4;
34}
35
36#if 0
37static size_t arena2big_szW (size_t sz) {
38 return sz - 4;
39}
40#endif
41
42/* pointer to top of an arena */
43static inline CELL *ArenaLimit(Term arena) {
44 CELL *arena_base = RepAppl(arena);
45 size_t szW = big2arena_szW(arena_base);
46 return arena_base + szW;
47}
48
49/* pointer to top of an arena */
50static inline CELL *ArenaPt(Term arena) { return RepAppl(arena); }
51
52static inline UInt ArenaSzW(Term arena) {
53 return big2arena_szW(RepAppl(arena));
54}
55
59typedef struct cell_space {
60 struct cell_space *parent; //> the ancestor
61 ssize_t oASP;
62 CELL *oH, *oHB; //> stacks above
63 CELL *arenaB, *arenaL; //> work area
64 size_t szW;
66
67inline static GlobalEntry *GetGlobalEntry(Atom at USES_REGS)
68/* get predicate entry for ap/arity; create it if neccessary. */
69{
70 Prop p0;
71 AtomEntry *ae = RepAtom(at);
72 GlobalEntry *new;
73
74 WRITE_LOCK(ae->ARWLock);
75 p0 = ae->PropsOfAE;
76 while (p0) {
77 GlobalEntry *pe = RepGlobalProp(p0);
78 if (pe->KindOfPE == GlobalProperty
79#if THREADS
80 && pe->owner_id == worker_id
81#endif
82 ) {
83 WRITE_UNLOCK(ae->ARWLock);
84 return pe;
85 }
86 p0 = pe->NextOfPE;
87 }
88 new = (GlobalEntry *) Yap_AllocAtomSpace(sizeof(*new));
89 INIT_RWLOCK(new->GRWLock);
90 new->KindOfPE = GlobalProperty;
91#if THREADS
92 new->owner_id = worker_id;
93#endif
94 new->NextGE = LOCAL_GlobalVariables;
95 LOCAL_GlobalVariables = new;
96 new->AtomOfGE = ae;
97 AddPropToAtom(ae, (PropEntry *) new);
98 RESET_VARIABLE(&new->global);
99 WRITE_UNLOCK(ae->ARWLock);
100 return new;
101}
102
103
104#endif
A cell_space is a short code region, where we want bindings to proceed locally.
Definition: YapArenas.h:59
Definition: Yatom.h:151