* collect2.c (main): In AIX specific computations for vector
[official-gcc.git] / libitm / local.cc
blob4f47ff2e5f6c7525d15cedded020868d2a714c34
1 /* Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
2 Contributed by Richard Henderson <rth@redhat.com>.
4 This file is part of the GNU Transactional Memory Library (libitm).
6 Libitm is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 Libitm is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
16 Under Section 7 of GPL version 3, you are granted additional
17 permissions described in the GCC Runtime Library Exception, version
18 3.1, as published by the Free Software Foundation.
20 You should have received a copy of the GNU General Public License and
21 a copy of the GCC Runtime Library Exception along with this program;
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 <http://www.gnu.org/licenses/>. */
25 #include "libitm_i.h"
27 namespace GTM HIDDEN {
29 struct gtm_undolog_entry
31 void *addr;
32 size_t len;
33 char saved[];
37 void
38 gtm_thread::commit_undolog ()
40 size_t i, n = undolog.size();
42 if (n > 0)
44 for (i = 0; i < n; ++i)
45 free (undolog[i]);
46 this->undolog.clear();
50 void
51 gtm_thread::rollback_undolog (size_t until_size)
53 size_t i, n = undolog.size();
55 if (n > 0)
57 for (i = n; i-- > until_size; )
59 gtm_undolog_entry *u = *undolog.pop();
60 if (u)
62 memcpy (u->addr, u->saved, u->len);
63 free (u);
69 /* Forget any references to PTR in the local log. */
71 void
72 gtm_thread::drop_references_undolog (const void *ptr, size_t len)
74 size_t i, n = undolog.size();
76 if (n > 0)
78 for (i = n; i > 0; i--)
80 gtm_undolog_entry *u = undolog[i];
81 /* ?? Do we need such granularity, or can we get away with
82 just comparing PTR and LEN. ?? */
83 if ((const char *)u->addr >= (const char *)ptr
84 && ((const char *)u->addr + u->len <= (const char *)ptr + len))
86 free (u);
87 undolog[i] = NULL;
93 void ITM_REGPARM
94 GTM_LB (const void *ptr, size_t len)
96 gtm_thread *tx = gtm_thr();
97 gtm_undolog_entry *undo;
99 undo = (gtm_undolog_entry *)
100 xmalloc (sizeof (struct gtm_undolog_entry) + len);
101 undo->addr = (void *) ptr;
102 undo->len = len;
104 tx->undolog.push()[0] = undo;
106 memcpy (undo->saved, ptr, len);
109 } // namespace GTM
111 using namespace GTM;
113 /* ??? Use configure to determine if aliases are supported. Or convince
114 the compiler to not just tail call this, but actually generate the
115 same_body_alias itself. */
116 void ITM_REGPARM
117 _ITM_LB (const void *ptr, size_t len)
119 GTM_LB (ptr, len);
122 #define ITM_LOG_DEF(T) \
123 void ITM_REGPARM _ITM_L##T (const _ITM_TYPE_##T *ptr) \
124 { GTM_LB (ptr, sizeof (*ptr)); }
126 ITM_LOG_DEF(U1)
127 ITM_LOG_DEF(U2)
128 ITM_LOG_DEF(U4)
129 ITM_LOG_DEF(U8)
130 ITM_LOG_DEF(F)
131 ITM_LOG_DEF(D)
132 ITM_LOG_DEF(E)
133 ITM_LOG_DEF(CF)
134 ITM_LOG_DEF(CD)
135 ITM_LOG_DEF(CE)