| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/indexeddb/IndexedDBClient.h" | 5 #include "modules/indexeddb/IndexedDBClient.h" |
| 6 #include "wtf/Atomics.h" | 6 #include "wtf/Atomics.h" |
| 7 | 7 |
| 8 namespace blink { | 8 namespace blink { |
| 9 | 9 |
| 10 static void* idbClientCreateFunction = nullptr; | 10 static void* idbClientCreateFunction = nullptr; |
| 11 | 11 |
| 12 void setIndexedDBClientCreateFunction(CreateIndexedDBClient createFunction) | 12 void setIndexedDBClientCreateFunction(CreateIndexedDBClient createFunction) |
| 13 { | 13 { |
| 14 // See web/IndexedDBClientImpl.h comment for some context. As the initializa
tion |
| 15 // of this IndexedDB client constructor now happens as context is set up for |
| 16 // threads, it is possible that setIndexedDBClientCreateFunction() will be |
| 17 // called more than once. Hence update atomicity is needed. |
| 14 #if ENABLE(ASSERT) | 18 #if ENABLE(ASSERT) |
| 15 CreateIndexedDBClient* currentFunction = reinterpret_cast<CreateIndexedDBCli
ent*>(acquireLoad(&idbClientCreateFunction)); | 19 CreateIndexedDBClient* currentFunction = reinterpret_cast<CreateIndexedDBCli
ent*>(acquireLoad(&idbClientCreateFunction)); |
| 16 ASSERT(!currentFunction || currentFunction == createFunction); | 20 ASSERT(!currentFunction || currentFunction == createFunction); |
| 17 #endif | 21 #endif |
| 18 releaseStore(&idbClientCreateFunction, reinterpret_cast<void*>(createFunctio
n)); | 22 releaseStore(&idbClientCreateFunction, reinterpret_cast<void*>(createFunctio
n)); |
| 19 } | 23 } |
| 20 | 24 |
| 21 IndexedDBClient* IndexedDBClient::create() | 25 IndexedDBClient* IndexedDBClient::create() |
| 22 { | 26 { |
| 23 CreateIndexedDBClient* createFunction = reinterpret_cast<CreateIndexedDBClie
nt*>(acquireLoad(&idbClientCreateFunction)); | 27 CreateIndexedDBClient* createFunction = reinterpret_cast<CreateIndexedDBClie
nt*>(acquireLoad(&idbClientCreateFunction)); |
| 24 ASSERT(createFunction); | 28 ASSERT(createFunction); |
| 25 // There's no reason why we need to allocate a new proxy each time, but | 29 // There's no reason why we need to allocate a new proxy each time, but |
| 26 // there's also no strong reason not to. | 30 // there's also no strong reason not to. |
| 27 return createFunction(); | 31 return createFunction(); |
| 28 } | 32 } |
| 29 | 33 |
| 30 } // namespace blink | 34 } // namespace blink |
| OLD | NEW |