Zero  0.1.0
row_cache.h
Go to the documentation of this file.
1 /* -*- mode:C++; c-basic-offset:4 -*-
2  Shore-kits -- Benchmark implementations for Shore-MT
3 
4  Copyright (c) 2007-2009
5  Data Intensive Applications and Systems Labaratory (DIAS)
6  Ecole Polytechnique Federale de Lausanne
7 
8  All Rights Reserved.
9 
10  Permission to use, copy, modify and distribute this software and
11  its documentation is hereby granted, provided that both the
12  copyright notice and this permission notice appear in all copies of
13  the software, derivative works or modified versions, and any
14  portions thereof, and that both notices appear in supporting
15  documentation.
16 
17  This code is distributed in the hope that it will be useful, but
18  WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. THE AUTHORS
20  DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
21  RESULTING FROM THE USE OF THIS SOFTWARE.
22 */
23 
34 #ifndef __ROW_CACHE_H
35 #define __ROW_CACHE_H
36 
37 #include "block_alloc.h"
38 #include "row.h"
39 
40 template<class TableDesc>
41 class row_cache_t {
42 public:
43  struct tuple_factory {
44  // WARNING: manually assign non-NULL before using the cache... Or Else
45  // CS TODO -- bad design! Implement new row cache
46  static TableDesc*& ptable() {
47  static TableDesc* _ptable;
48  return _ptable;
49  }
50 
51  static table_row_t* construct(void* ptr) {
52  return new(ptr) table_row_t(ptable());
53  }
54 
55  static void destroy(table_row_t* t) {
56  t->~table_row_t();
57  }
58 
59  static void reset(table_row_t* t) {
60  t->reset();
61  }
62 
63  // TODO: figure out how to build in the areprow stuff?
64  // IP: The areprow stuff should use another block allocator for char*[some-max-size]
66  return t;
67  }
68  };
69 
70 private:
71  typedef object_cache<table_row_t, tuple_factory> Cache;
72 
73  Cache _cache;
74 
75 public:
76 
77  /* Return an unused object, if cache empty allocate and return a new one
78  */
80  return _cache.acquire();
81  }
82 
83  /* Returns an object to the cache. The object is reset and put on the
84  * free list.
85  */
86  static void giveback(table_row_t* ptn) {
87  assert (ptn);
88  Cache::release(ptn);
89  }
90 }; // EOF: row_cache_t
91 
92 
93 #endif // __ROW_CACHE_H
static table_row_t * init(table_row_t *t)
Definition: row_cache.h:65
Definition: row_cache.h:43
static void giveback(table_row_t *ptn)
Definition: row_cache.h:86
static void destroy(table_row_t *t)
Definition: row_cache.h:55
Definition: row_cache.h:41
virtual ~table_row_t()
Definition: row.cpp:138
void reset()
Definition: row.h:316
table_row_t * borrow()
Definition: row_cache.h:79
static TableDesc *& ptable()
Definition: row_cache.h:46
Cache _cache
Definition: row_cache.h:73
static void reset(table_row_t *t)
Definition: row_cache.h:59
object_cache< table_row_t, tuple_factory > Cache
Definition: row_cache.h:71
static table_row_t * construct(void *ptr)
Definition: row_cache.h:51
: Base class for records (rows) of tables in Shore
Definition: row.h:147