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

Side by Side Diff: Source/platform/blob/BlobRegistry.cpp

Issue 794223003: Cheaper thread-safe atomic initialization of static references. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add type check for initial value Created 5 years, 11 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 98
99 static WebBlobRegistry* blobRegistry() 99 static WebBlobRegistry* blobRegistry()
100 { 100 {
101 return Platform::current()->blobRegistry(); 101 return Platform::current()->blobRegistry();
102 } 102 }
103 103
104 typedef HashMap<String, RefPtr<SecurityOrigin>> BlobURLOriginMap; 104 typedef HashMap<String, RefPtr<SecurityOrigin>> BlobURLOriginMap;
105 static ThreadSpecific<BlobURLOriginMap>& originMap() 105 static ThreadSpecific<BlobURLOriginMap>& originMap()
106 { 106 {
107 // We want to create the BlobOriginCache exactly once because it is shared b y all the threads. 107 // We want to create the BlobOriginCache exactly once because it is shared b y all the threads.
108 AtomicallyInitializedStatic(BlobOriginCache*, cache = new BlobOriginCache); 108 AtomicallyInitializedStaticReference(BlobOriginCache, cache, new BlobOriginC ache);
109 (void)cache; // BlobOriginCache's constructor does the interesting work. 109 (void)cache; // BlobOriginCache's constructor does the interesting work.
110 110
111 AtomicallyInitializedStatic(ThreadSpecific<BlobURLOriginMap>*, map = new Thr eadSpecific<BlobURLOriginMap>); 111 AtomicallyInitializedStaticReference(ThreadSpecific<BlobURLOriginMap>, map, new ThreadSpecific<BlobURLOriginMap>);
112 return *map; 112 return map;
113 } 113 }
114 114
115 static void saveToOriginMap(SecurityOrigin* origin, const KURL& url) 115 static void saveToOriginMap(SecurityOrigin* origin, const KURL& url)
116 { 116 {
117 // If the blob URL contains null origin, as in the context with unique 117 // If the blob URL contains null origin, as in the context with unique
118 // security origin or file URL, save the mapping between url and origin so 118 // security origin or file URL, save the mapping between url and origin so
119 // that the origin can be retrived when doing security origin check. 119 // that the origin can be retrived when doing security origin check.
120 if (origin && BlobURL::getOrigin(url) == "null") 120 if (origin && BlobURL::getOrigin(url) == "null")
121 originMap()->add(url.string(), origin); 121 originMap()->add(url.string(), origin);
122 } 122 }
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 } 292 }
293 293
294 SecurityOrigin* BlobOriginCache::cachedOrigin(const KURL& url) 294 SecurityOrigin* BlobOriginCache::cachedOrigin(const KURL& url)
295 { 295 {
296 if (url.protocolIs("blob")) 296 if (url.protocolIs("blob"))
297 return originMap()->get(url.string()); 297 return originMap()->get(url.string());
298 return 0; 298 return 0;
299 } 299 }
300 300
301 } // namespace blink 301 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698