1 // Copyright (c) 2018 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that 3 // can be found in the LICENSE file. 4 5 #include "tests/cefclient/browser/util_gtk.h" 6 7 #include <gdk/gdk.h> 8 9 namespace client { 10 11 base::PlatformThreadId ScopedGdkThreadsEnter::locked_thread_ = 12 kInvalidPlatformThreadId; 13 ScopedGdkThreadsEnter()14ScopedGdkThreadsEnter::ScopedGdkThreadsEnter() { 15 // The GDK lock is not reentrant, so don't try to lock again if the current 16 // thread already holds it. 17 base::PlatformThreadId current_thread = base::PlatformThread::CurrentId(); 18 take_lock_ = current_thread != locked_thread_; 19 20 if (take_lock_) { 21 gdk_threads_enter(); 22 locked_thread_ = current_thread; 23 } 24 } 25 ~ScopedGdkThreadsEnter()26ScopedGdkThreadsEnter::~ScopedGdkThreadsEnter() { 27 if (take_lock_) { 28 locked_thread_ = kInvalidPlatformThreadId; 29 gdk_threads_leave(); 30 } 31 } 32 33 } // namespace client 34