2 * Eddie Kohler, Yandong Mao, Robert Morris
3 * Copyright (c) 2012-2014 President and Fellows of Harvard College
4 * Copyright (c) 2012-2014 Massachusetts Institute of Technology
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, subject to the conditions
9 * listed in the Masstree LICENSE file. These conditions include: you must
10 * preserve this copyright notice, and you cannot mention the copyright
11 * holders in advertising related to the Software without their permission.
12 * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
13 * notice is a summary of the Masstree LICENSE file; the license in that file
17 #include "value_array.hh"
20 value_array* value_array::make_sized_row(int ncol, kvtimestamp_t ts,
23 tv = (value_array *) ti.allocate(shallow_size(ncol), memtag_value);
26 memset(tv->cols_, 0, sizeof(tv->cols_[0]) * ncol);
30 value_array* value_array::update(const Json* first, const Json* last,
31 kvtimestamp_t ts, threadinfo& ti) const {
32 masstree_precondition(ts >= ts_);
33 unsigned ncol = std::max(int(ncol_), int(last[-2].as_i()) + 1);
34 value_array* row = (value_array*) ti.allocate(shallow_size(ncol), memtag_value);
37 memcpy(row->cols_, cols_, ncol_ * sizeof(cols_[0]));
38 memset(row->cols_ + ncol_, 0, (ncol - ncol_) * sizeof(cols_[0]));
39 for (; first != last; first += 2)
40 row->cols_[first[0].as_u()] = make_column(first[1].as_s(), ti);
44 void value_array::deallocate(threadinfo& ti) {
45 for (short i = 0; i < ncol_; ++i)
46 deallocate_column(cols_[i], ti);
47 ti.deallocate(this, shallow_size(), memtag_value);
50 void value_array::deallocate_rcu(threadinfo& ti) {
51 for (short i = 0; i < ncol_; ++i)
52 deallocate_column_rcu(cols_[i], ti);
53 ti.deallocate_rcu(this, shallow_size(), memtag_value);
56 void value_array::deallocate_rcu_after_update(const Json* first, const Json* last, threadinfo& ti) {
57 for (; first != last && first[0].as_u() < unsigned(ncol_); first += 2)
58 deallocate_column_rcu(cols_[first[0].as_u()], ti);
59 ti.deallocate_rcu(this, shallow_size(), memtag_value);
62 void value_array::deallocate_after_failed_update(const Json* first, const Json* last, threadinfo& ti) {
63 for (; first != last; first += 2)
64 deallocate_column(cols_[first[0].as_u()], ti);
65 ti.deallocate(this, shallow_size(), memtag_value);