@@ -26,13 +26,6 @@
namespace GTM HIDDEN {
-struct gtm_alloc_action
-{
- void (*free_fn)(void *);
- bool allocated;
-};
-
-
void
gtm_transaction::record_allocation (void *ptr, void (*free_fn)(void *))
{
@@ -40,21 +40,23 @@ static _ITM_transactionId_t global_tid;
/* Allocate a transaction structure. Reuse an old one if possible. */
-static gtm_transaction *
-alloc_tx (void)
+void *
+GTM::gtm_transaction::operator new (size_t s)
{
- gtm_transaction *tx;
gtm_thread *thr = gtm_thr ();
+ void *tx;
+
+ assert(s == sizeof(gtm_transaction));
if (thr->free_tx_count == 0)
- tx = static_cast<gtm_transaction *>(xmalloc (sizeof (gtm_transaction)));
+ tx = xmalloc (sizeof (gtm_transaction));
else
{
thr->free_tx_count--;
tx = thr->free_tx[thr->free_tx_idx];
thr->free_tx_idx = (thr->free_tx_idx + 1) % gtm_thread::MAX_FREE_TX;
}
- memset (tx, 0, sizeof (*tx));
+ memset (tx, 0, sizeof (gtm_transaction));
return tx;
}
@@ -64,8 +66,8 @@ alloc_tx (void)
as the jmpbuf is used immediately after calling this function. Thus
the requirement that this queue be per-thread. */
-static void
-free_tx (gtm_transaction *tx)
+void
+GTM::gtm_transaction::operator delete(void *tx)
{
gtm_thread *thr = gtm_thr ();
unsigned idx
@@ -92,7 +94,7 @@ GTM::gtm_transaction::begin_transaction (uint32_t prop, const gtm_jmpbuf *jb)
setup_gtm_thr ();
- tx = alloc_tx ();
+ tx = new gtm_transaction;
tx->prop = prop;
tx->prev = gtm_tx();
@@ -185,7 +187,7 @@ _ITM_abortTransaction (_ITM_abortReason reason)
gtm_transaction::serial_lock.read_unlock ();
set_gtm_tx (tx->prev);
- free_tx (tx);
+ delete tx;
GTM_longjmp (&tx->jb, a_abortTransaction | a_restoreLiveVariables, tx->prop);
}
@@ -211,7 +213,7 @@ GTM::gtm_transaction::trycommit_and_finalize ()
{
gtm_disp()->fini ();
set_gtm_tx (this->prev);
- free_tx (this);
+ delete this;
if (this->state & gtm_transaction::STATE_SERIAL)
gtm_transaction::serial_lock.write_unlock ();
else
@@ -47,7 +47,7 @@ struct gtm_thread
static const unsigned MAX_FREE_TX = 8;
// A queue of free gtm_transaction structs.
- gtm_transaction *free_tx[MAX_FREE_TX];
+ void *free_tx[MAX_FREE_TX];
unsigned free_tx_idx, free_tx_count;
// The value returned by _ITM_getThreadnum to identify this thread.
@@ -149,8 +149,13 @@ enum gtm_restart_reason
NUM_RESTARTS
};
-// This type is private to alloc.c.
-struct gtm_alloc_action;
+// This type is private to alloc.c, but needs to be defined so that
+// the template used inside gtm_transaction can instantiate.
+struct gtm_alloc_action
+{
+ void (*free_fn)(void *);
+ bool allocated;
+};
// This type is private to local.c.
struct gtm_local_undo;
@@ -228,6 +233,9 @@ struct gtm_transaction
bool trycommit_and_finalize ();
void restart (gtm_restart_reason) ITM_NORETURN;
+ static void *operator new(size_t);
+ static void operator delete(void *);
+
// Invoked from assembly language, thus the "asm" specifier on
// the name, avoiding complex name mangling.
static uint32_t begin_transaction(uint32_t, const gtm_jmpbuf *)