initialization.cc 780 B

12345678910111213141516171819202122232425262728
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "sql/initialization.h"
  5. #include "base/no_destructor.h"
  6. #include "base/synchronization/lock.h"
  7. #include "base/trace_event/trace_event.h"
  8. #include "third_party/sqlite/sqlite3.h"
  9. namespace sql {
  10. void EnsureSqliteInitialized() {
  11. // sqlite3_initialize() uses double-checked locking and thus can have
  12. // data races.
  13. static base::NoDestructor<base::Lock> sqlite_init_lock;
  14. base::AutoLock auto_lock(*sqlite_init_lock);
  15. static bool first_call = true;
  16. if (first_call) {
  17. TRACE_EVENT0("sql", "EnsureSqliteInitialized");
  18. sqlite3_initialize();
  19. first_call = false;
  20. }
  21. }
  22. } // namespace sql