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 #ifndef CEF_TESTS_CEFCLIENT_BROWSER_UTIL_GTK_H_ 6 #define CEF_TESTS_CEFCLIENT_BROWSER_UTIL_GTK_H_ 7 #pragma once 8 9 #include "include/base/cef_macros.h" 10 #include "include/base/cef_platform_thread.h" 11 12 namespace client { 13 14 // Scoped helper that manages the global GDK lock by calling gdk_threads_enter() 15 // and gdk_threads_leave(). The lock is not reentrant so this helper implements 16 // additional checking to avoid deadlocks. 17 // 18 // When using GTK in multi-threaded mode you must do the following: 19 // 1. Call gdk_threads_init() before making any other GTK/GDK/GLib calls. 20 // 2. Acquire the global lock before making any GTK/GDK calls, and release the 21 // lock afterwards. This should only be done with callbacks that do not 22 // originate from GTK signals (because those callbacks already hold the 23 // lock). 24 // 25 // See https://www.geany.org/manual/gtk/gtk-faq/x482.html for more information. 26 class ScopedGdkThreadsEnter { 27 public: 28 ScopedGdkThreadsEnter(); 29 ~ScopedGdkThreadsEnter(); 30 31 private: 32 bool take_lock_; 33 34 static base::PlatformThreadId locked_thread_; 35 36 DISALLOW_COPY_AND_ASSIGN(ScopedGdkThreadsEnter); 37 }; 38 39 } // namespace client 40 41 #endif // CEF_TESTS_CEFCLIENT_BROWSER_UTIL_GTK_H_ 42