Annotation of researchv10no/cmd/cfront/libC/misc/Pool.c, revision 1.1.1.1

1.1       root        1: #include <Pool.h>
                      2: 
                      3: static const round = 4;                // most stringent alignment, in chars
                      4: 
                      5: // offset in chars of the data part of a block
                      6: static const blockoff = (sizeof(Block_header)+round-1) & -round;
                      7: 
                      8: Block_pool::Block_pool (unsigned n)
                      9: {
                     10:        sz = n;
                     11:        head = 0;
                     12: }
                     13: 
                     14: Block_pool::~Block_pool()
                     15: {
                     16:        while (head) {
                     17:                Block_header* b = head;
                     18:                head = head->next;
                     19:                delete (char*) b;
                     20:        }
                     21: }
                     22: 
                     23: char*
                     24: Block_pool::expand()
                     25: {
                     26:        Block_header* b = (Block_header*) new char[size()+blockoff];
                     27:        b->next = head;
                     28:        head = b;
                     29:        return ((char*) b) + blockoff;
                     30: }
                     31: 
                     32: 
                     33: // largest multiple of q that is <= p
                     34: static unsigned
                     35: floor (unsigned p, unsigned q)
                     36: {
                     37:        return p - p % (q + (q==0));
                     38: }
                     39: 
                     40: // smallest multiple of q that is >= p
                     41: static unsigned
                     42: ceil (unsigned p, unsigned q)
                     43: {
                     44:        return floor (p + q - 1, q);
                     45: }
                     46: 
                     47: Pool::Pool(unsigned n): (ceil (1000, n))
                     48: {
                     49:        elsize = (n + (n == 0) + round - 1) & -round;
                     50:        count = Block_pool::size()/elsize;
                     51:        head = 0;
                     52: }
                     53: 
                     54: void
                     55: Pool::grow()
                     56: {
                     57:        register char* p = expand();
                     58:        register int n = count;
                     59: 
                     60:        while (--n >= 0) {
                     61:                register Pool_element_header* ph = (Pool_element_header*) p;
                     62:                ph->next = head;
                     63:                head = ph;
                     64:                p += elsize;
                     65:        }
                     66: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.