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

Side by Side Diff: Source/platform/heap/Visitor.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) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 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 30 matching lines...) Expand all
41 int GCInfoTable::s_gcInfoIndex = 0; 41 int GCInfoTable::s_gcInfoIndex = 0;
42 42
43 size_t GCInfoTable::s_gcInfoTableSize = 0; 43 size_t GCInfoTable::s_gcInfoTableSize = 0;
44 GCInfo const** s_gcInfoTable = nullptr; 44 GCInfo const** s_gcInfoTable = nullptr;
45 45
46 void GCInfoTable::ensureGCInfoIndex(const GCInfo* gcInfo, size_t* gcInfoIndexSlo t) 46 void GCInfoTable::ensureGCInfoIndex(const GCInfo* gcInfo, size_t* gcInfoIndexSlo t)
47 { 47 {
48 ASSERT(gcInfo); 48 ASSERT(gcInfo);
49 ASSERT(gcInfoIndexSlot); 49 ASSERT(gcInfoIndexSlot);
50 // Keep a global GCInfoTable lock while allocating a new slot. 50 // Keep a global GCInfoTable lock while allocating a new slot.
51 AtomicallyInitializedStatic(Mutex&, mutex = *new Mutex); 51 AtomicallyInitializedStaticReference(Mutex, mutex, new Mutex);
52 MutexLocker locker(mutex); 52 MutexLocker locker(mutex);
53 53
54 // If more than one thread ends up allocating a slot for 54 // If more than one thread ends up allocating a slot for
55 // the same GCInfo, have later threads reuse the slot 55 // the same GCInfo, have later threads reuse the slot
56 // allocated by the first. 56 // allocated by the first.
57 if (*gcInfoIndexSlot) 57 if (*gcInfoIndexSlot)
58 return; 58 return;
59 59
60 int index = ++s_gcInfoIndex; 60 int index = ++s_gcInfoIndex;
61 size_t gcInfoIndex = static_cast<size_t>(index); 61 size_t gcInfoIndex = static_cast<size_t>(index);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 #if !defined(COMPONENT_BUILD) 102 #if !defined(COMPONENT_BUILD)
103 // On component builds we cannot compare the gcInfos as they are statically 103 // On component builds we cannot compare the gcInfos as they are statically
104 // defined in each of the components and hence will not match. 104 // defined in each of the components and hence will not match.
105 BaseHeapPage* page = pageFromObject(payload); 105 BaseHeapPage* page = pageFromObject(payload);
106 ASSERT(page->orphaned() || HeapObjectHeader::fromPayload(payload)->gcInfoInd ex() == gcInfoIndex); 106 ASSERT(page->orphaned() || HeapObjectHeader::fromPayload(payload)->gcInfoInd ex() == gcInfoIndex);
107 #endif 107 #endif
108 } 108 }
109 #endif 109 #endif
110 110
111 } 111 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698