OSDN Git Service

libitm: Configure for gas cfi pseudo ops.
[pf3gnuchains/gcc-fork.git] / libitm / local.cc
1 /* Copyright (C) 2008, 2009, 2011 Free Software Foundation, Inc.
2    Contributed by Richard Henderson <rth@redhat.com>.
3
4    This file is part of the GNU Transactional Memory Library (libitm).
5
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.
10
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.
15
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.
19
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/>.  */
24
25 #include "libitm_i.h"
26
27 namespace GTM HIDDEN {
28
29 struct gtm_undolog_entry
30 {
31   void *addr;
32   size_t len;
33   char saved[];
34 };
35
36
37 void
38 gtm_thread::commit_undolog ()
39 {
40   size_t i, n = undolog.size();
41
42   if (n > 0)
43     {
44       for (i = 0; i < n; ++i)
45         free (undolog[i]);
46       this->undolog.clear();
47     }
48 }
49
50 void
51 gtm_thread::rollback_undolog (size_t until_size)
52 {
53   size_t i, n = undolog.size();
54
55   if (n > 0)
56     {
57       for (i = n; i-- > until_size; )
58         {
59           gtm_undolog_entry *u = *undolog.pop();
60           if (u)
61             {
62               memcpy (u->addr, u->saved, u->len);
63               free (u);
64             }
65         }
66     }
67 }
68
69 /* Forget any references to PTR in the local log.  */
70
71 void
72 gtm_thread::drop_references_undolog (const void *ptr, size_t len)
73 {
74   size_t i, n = undolog.size();
75
76   if (n > 0)
77     {
78       for (i = n; i > 0; i--)
79         {
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))
85             {
86               free (u);
87               undolog[i] = NULL;
88             }
89         }
90     }
91 }
92
93 void ITM_REGPARM
94 GTM_LB (const void *ptr, size_t len)
95 {
96   gtm_thread *tx = gtm_thr();
97   gtm_undolog_entry *undo;
98
99   undo = (gtm_undolog_entry *)
100       xmalloc (sizeof (struct gtm_undolog_entry) + len);
101   undo->addr = (void *) ptr;
102   undo->len = len;
103
104   tx->undolog.push()[0] = undo;
105
106   memcpy (undo->saved, ptr, len);
107 }
108
109 } // namespace GTM
110
111 using namespace GTM;
112
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)
118 {
119   GTM_LB (ptr, len);
120 }
121
122 #define ITM_LOG_DEF(T) \
123 void ITM_REGPARM _ITM_L##T (const _ITM_TYPE_##T *ptr) \
124 { GTM_LB (ptr, sizeof (*ptr)); }
125
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)