Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: Source/modules/webdatabase/Database.cpp

Issue 874203002: Add a thread-safety assertion in DEFINE_STATIC_LOCAL (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: added noncopyable Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2013 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 { 141 {
142 AtomicallyInitializedStaticReference(RecursiveMutex, mutex, new RecursiveMut ex); 142 AtomicallyInitializedStaticReference(RecursiveMutex, mutex, new RecursiveMut ex);
143 return mutex; 143 return mutex;
144 } 144 }
145 145
146 typedef HashMap<DatabaseGuid, String> GuidVersionMap; 146 typedef HashMap<DatabaseGuid, String> GuidVersionMap;
147 static GuidVersionMap& guidToVersionMap() 147 static GuidVersionMap& guidToVersionMap()
148 { 148 {
149 // Ensure the the mutex is locked. 149 // Ensure the the mutex is locked.
150 ASSERT(guidMutex().locked()); 150 ASSERT(guidMutex().locked());
151 DEFINE_STATIC_LOCAL(GuidVersionMap, map, ()); 151 DEFINE_STATIC_LOCAL_NOASSERT(GuidVersionMap, map, ());
152 return map; 152 return map;
153 } 153 }
154 154
155 // NOTE: Caller must lock guidMutex(). 155 // NOTE: Caller must lock guidMutex().
156 static inline void updateGuidVersionMap(DatabaseGuid guid, String newVersion) 156 static inline void updateGuidVersionMap(DatabaseGuid guid, String newVersion)
157 { 157 {
158 // Ensure the the mutex is locked. 158 // Ensure the the mutex is locked.
159 ASSERT(guidMutex().locked()); 159 ASSERT(guidMutex().locked());
160 160
161 // Note: It is not safe to put an empty string into the guidToVersionMap() 161 // Note: It is not safe to put an empty string into the guidToVersionMap()
162 // map. That's because the map is cross-thread, but empty strings are 162 // map. That's because the map is cross-thread, but empty strings are
163 // per-thread. The copy() function makes a version of the string you can 163 // per-thread. The copy() function makes a version of the string you can
164 // use on the current thread, but we need a string we can keep in a 164 // use on the current thread, but we need a string we can keep in a
165 // cross-thread data structure. 165 // cross-thread data structure.
166 // FIXME: This is a quite-awkward restriction to have to program with. 166 // FIXME: This is a quite-awkward restriction to have to program with.
167 167
168 // Map null string to empty string (see comment above). 168 // Map null string to empty string (see comment above).
169 guidToVersionMap().set(guid, newVersion.isEmpty() ? String() : newVersion.is olatedCopy()); 169 guidToVersionMap().set(guid, newVersion.isEmpty() ? String() : newVersion.is olatedCopy());
170 } 170 }
171 171
172 typedef HashMap<DatabaseGuid, HashSet<Database*>*> GuidDatabaseMap; 172 typedef HashMap<DatabaseGuid, HashSet<Database*>*> GuidDatabaseMap;
173 static GuidDatabaseMap& guidToDatabaseMap() 173 static GuidDatabaseMap& guidToDatabaseMap()
174 { 174 {
175 // Ensure the the mutex is locked. 175 // Ensure the the mutex is locked.
176 ASSERT(guidMutex().locked()); 176 ASSERT(guidMutex().locked());
177 DEFINE_STATIC_LOCAL(GuidDatabaseMap, map, ()); 177 DEFINE_STATIC_LOCAL_NOASSERT(GuidDatabaseMap, map, ());
178 return map; 178 return map;
179 } 179 }
180 180
181 static DatabaseGuid guidForOriginAndName(const String& origin, const String& nam e) 181 static DatabaseGuid guidForOriginAndName(const String& origin, const String& nam e)
182 { 182 {
183 // Ensure the the mutex is locked. 183 // Ensure the the mutex is locked.
184 ASSERT(guidMutex().locked()); 184 ASSERT(guidMutex().locked());
185 185
186 String stringID = origin + "/" + name; 186 String stringID = origin + "/" + name;
187 187
188 typedef HashMap<String, int> IDGuidMap; 188 typedef HashMap<String, int> IDGuidMap;
189 DEFINE_STATIC_LOCAL(IDGuidMap, stringIdentifierToGUIDMap, ()); 189 DEFINE_STATIC_LOCAL_NOASSERT(IDGuidMap, stringIdentifierToGUIDMap, ());
190 DatabaseGuid guid = stringIdentifierToGUIDMap.get(stringID); 190 DatabaseGuid guid = stringIdentifierToGUIDMap.get(stringID);
191 if (!guid) { 191 if (!guid) {
192 static int currentNewGUID = 1; 192 static int currentNewGUID = 1;
193 guid = currentNewGUID++; 193 guid = currentNewGUID++;
194 stringIdentifierToGUIDMap.set(stringID, guid); 194 stringIdentifierToGUIDMap.set(stringID, guid);
195 } 195 }
196 196
197 return guid; 197 return guid;
198 } 198 }
199 199
(...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 SecurityOrigin* Database::securityOrigin() const 920 SecurityOrigin* Database::securityOrigin() const
921 { 921 {
922 if (executionContext()->isContextThread()) 922 if (executionContext()->isContextThread())
923 return m_contextThreadSecurityOrigin.get(); 923 return m_contextThreadSecurityOrigin.get();
924 if (databaseContext()->databaseThread()->isDatabaseThread()) 924 if (databaseContext()->databaseThread()->isDatabaseThread())
925 return m_databaseThreadSecurityOrigin.get(); 925 return m_databaseThreadSecurityOrigin.get();
926 return 0; 926 return 0;
927 } 927 }
928 928
929 } // namespace blink 929 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698