Permalink
Switch branches/tags
snapshots/gcc-4.8-20120701 snapshots/gcc-4.8-20120624 snapshots/gcc-4.8-20120617 snapshots/gcc-4.8-20120610 snapshots/gcc-4.8-20120603 snapshots/gcc-4.8-20120527 snapshots/gcc-4.8-20120520 snapshots/gcc-4.8-20120513 snapshots/gcc-4.8-20120506 snapshots/gcc-4.8-20120429 snapshots/gcc-4.8-20120422 snapshots/gcc-4.8-20120415 snapshots/gcc-4.8-20120408 snapshots/gcc-4.8-20120401 snapshots/gcc-4.8-20120325 snapshots/gcc-4.8-20120318 snapshots/gcc-4.8-20120311 snapshots/gcc-4.8-20120304 snapshots/gcc-4.8-20120302 snapshots/gcc-4.7.1-RC-20120606 snapshots/gcc-4.7.0-RC-20120314 snapshots/gcc-4.7.0-RC-20120302 snapshots/gcc-4.7-20120707 snapshots/gcc-4.7-20120630 snapshots/gcc-4.7-20120623 snapshots/gcc-4.7-20120616 snapshots/gcc-4.7-20120609 snapshots/gcc-4.7-20120602 snapshots/gcc-4.7-20120526 snapshots/gcc-4.7-20120519 snapshots/gcc-4.7-20120512 snapshots/gcc-4.7-20120505 snapshots/gcc-4.7-20120428 snapshots/gcc-4.7-20120421 snapshots/gcc-4.7-20120414 snapshots/gcc-4.7-20120407 snapshots/gcc-4.7-20120331 snapshots/gcc-4.7-20120324 snapshots/gcc-4.7-20120225 snapshots/gcc-4.7-20120218 snapshots/gcc-4.7-20120211 snapshots/gcc-4.7-20120204 snapshots/gcc-4.7-20120128 snapshots/gcc-4.7-20120121 snapshots/gcc-4.7-20120114 snapshots/gcc-4.7-20120107 snapshots/gcc-4.7-20111231 snapshots/gcc-4.7-20111224 snapshots/gcc-4.7-20111217 snapshots/gcc-4.7-20111210 snapshots/gcc-4.7-20111203 snapshots/gcc-4.7-20111126 snapshots/gcc-4.7-20111119 snapshots/gcc-4.7-20111112 snapshots/gcc-4.7-20111105 snapshots/gcc-4.7-20111029 snapshots/gcc-4.7-20111022 snapshots/gcc-4.7-20111015 snapshots/gcc-4.7-20111008 snapshots/gcc-4.7-20111001 snapshots/gcc-4.7-20110924 snapshots/gcc-4.7-20110917 snapshots/gcc-4.7-20110910 snapshots/gcc-4.7-20110903 snapshots/gcc-4.7-20110827 snapshots/gcc-4.7-20110820 snapshots/gcc-4.7-20110813 snapshots/gcc-4.7-20110806 snapshots/gcc-4.7-20110730 snapshots/gcc-4.7-20110723 snapshots/gcc-4.7-20110716 snapshots/gcc-4.7-20110709 snapshots/gcc-4.7-20110702 snapshots/gcc-4.7-20110625 snapshots/gcc-4.7-20110618 snapshots/gcc-4.7-20110611 snapshots/gcc-4.7-20110604 snapshots/gcc-4.7-20110528 snapshots/gcc-4.7-20110521 snapshots/gcc-4.7-20110514 snapshots/gcc-4.7-20110507 snapshots/gcc-4.7-20110430 snapshots/gcc-4.7-20110423 snapshots/gcc-4.7-20110416 snapshots/gcc-4.7-20110409 snapshots/gcc-4.7-20110402 snapshots/gcc-4.6.3-RC-20120223 snapshots/gcc-4.6.2-RC-20111019 snapshots/gcc-4.6.1-RC-20110620 snapshots/gcc-4.6-20120706 snapshots/gcc-4.6-20120629 snapshots/gcc-4.6-20120622 snapshots/gcc-4.6-20120615 snapshots/gcc-4.6-20120608 snapshots/gcc-4.6-20120601 snapshots/gcc-4.6-20120525 snapshots/gcc-4.6-20120518 snapshots/gcc-4.6-20120511 snapshots/gcc-4.6-20120504 snapshots/gcc-4.6-20120427
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
130 lines (108 sloc) 3.63 KB
/* Copyright (C) 2009, 2011 Free Software Foundation, Inc.
Contributed by Richard Henderson <rth@redhat.com>.
This file is part of the GNU Transactional Memory Library (libitm).
Libitm is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
Under Section 7 of GPL version 3, you are granted additional
permissions described in the GCC Runtime Library Exception, version
3.1, as published by the Free Software Foundation.
You should have received a copy of the GNU General Public License and
a copy of the GCC Runtime Library Exception along with this program;
see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
<http://www.gnu.org/licenses/>. */
#include "libitm_i.h"
namespace GTM HIDDEN {
void
gtm_thread::record_allocation (void *ptr, void (*free_fn)(void *))
{
uintptr_t iptr = (uintptr_t) ptr;
gtm_alloc_action *a = this->alloc_actions.find(iptr);
if (a == 0)
a = this->alloc_actions.insert(iptr);
a->free_fn = free_fn;
a->allocated = true;
}
void
gtm_thread::forget_allocation (void *ptr, void (*free_fn)(void *))
{
uintptr_t iptr = (uintptr_t) ptr;
gtm_alloc_action *a = this->alloc_actions.find(iptr);
if (a == 0)
a = this->alloc_actions.insert(iptr);
a->free_fn = free_fn;
a->allocated = false;
}
namespace {
struct commit_cb_data {
aa_tree<uintptr_t, gtm_alloc_action>* parent;
bool revert_p;
};
}
static void
commit_allocations_2 (uintptr_t key, gtm_alloc_action *a, void *data)
{
void *ptr = (void *)key;
commit_cb_data *cb_data = static_cast<commit_cb_data *>(data);
if (cb_data->revert_p)
{
// Roll back nested allocations.
if (a->allocated)
a->free_fn (ptr);
}
else
{
if (a->allocated)
{
// Add nested allocations to parent transaction.
gtm_alloc_action* a_parent = cb_data->parent->insert(key);
*a_parent = *a;
}
else
{
// ??? We could eliminate a parent allocation that matches this
// memory release, if we had support for removing all accesses
// to this allocation from the transaction's undo and redo logs
// (otherwise, the parent transaction's undo or redo might write to
// data that is already shared again because of calling free()).
// We don't have this support currently, and the benefit of this
// optimization is unknown, so just add it to the parent.
gtm_alloc_action* a_parent;
a_parent = cb_data->parent->insert(key);
*a_parent = *a;
}
}
}
static void
commit_allocations_1 (uintptr_t key, gtm_alloc_action *a, void *cb_data)
{
void *ptr = (void *)key;
uintptr_t revert_p = (uintptr_t) cb_data;
if (a->allocated == revert_p)
a->free_fn (ptr);
}
/* Permanently commit allocated memory during transaction.
REVERT_P is true if instead of committing the allocations, we want
to roll them back (and vice versa). */
void
gtm_thread::commit_allocations (bool revert_p,
aa_tree<uintptr_t, gtm_alloc_action>* parent)
{
if (parent)
{
commit_cb_data cb_data;
cb_data.parent = parent;
cb_data.revert_p = revert_p;
this->alloc_actions.traverse (commit_allocations_2, &cb_data);
}
else
this->alloc_actions.traverse (commit_allocations_1,
(void *)(uintptr_t)revert_p);
this->alloc_actions.clear ();
}
} // namespace GTM