Loading system/stack/btu/btu_task.cc +19 −0 Original line number Diff line number Diff line Loading @@ -126,3 +126,22 @@ void main_thread_start_up() { } void main_thread_shut_down() { main_thread.ShutDown(); } bool is_on_main_thread() { // Pthreads doesn't have the concept of a thread ID, so we have to reach down // into the kernel. #if defined(OS_MACOSX) return main_thread.GetThreadId() == pthread_mach_thread_np(pthread_self()); #elif defined(OS_LINUX) #include <sys/syscall.h> /* For SYS_xxx definitions */ #include <unistd.h> return main_thread.GetThreadId() == syscall(__NR_gettid); #elif defined(OS_ANDROID) #include <sys/types.h> #include <unistd.h> return main_thread.GetThreadId() == gettid(); #else LOG(ERROR) << __func__ << "Unable to determine if on main thread"; return true; #endif } system/stack/include/btu.h +1 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ bt_status_t do_in_main_thread_delayed(const base::Location& from_here, base::OnceClosure task, const base::TimeDelta& delay); bool is_on_main_thread(); using BtMainClosure = std::function<void()>; void post_on_bt_main(BtMainClosure closure); Loading system/test/common/main_handler.cc +21 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ #include <base/callback_forward.h> #include <base/location.h> #include <base/time/time.h> #include <sys/types.h> #include <unistd.h> #include <functional> #include <future> Loading Loading @@ -75,3 +77,22 @@ void sync_main_handler() { post_on_bt_main([&promise]() { promise.set_value(); }); future.wait_for(std::chrono::milliseconds(sync_timeout_in_ms)); }; bool is_on_main_thread() { // Pthreads doesn't have the concept of a thread ID, so we have to reach down // into the kernel. #if defined(OS_MACOSX) return main_thread.GetThreadId() == pthread_mach_thread_np(pthread_self()); #elif defined(OS_LINUX) #include <sys/syscall.h> /* For SYS_xxx definitions */ #include <unistd.h> return main_thread.GetThreadId() == syscall(__NR_gettid); #elif defined(OS_ANDROID) #include <sys/types.h> #include <unistd.h> return main_thread.GetThreadId() == gettid(); #else LOG(ERROR) << __func__ << "Unable to determine if on main thread"; return true; #endif } system/test/common/main_handler.h +1 −0 Original line number Diff line number Diff line Loading @@ -37,3 +37,4 @@ void main_thread_shut_down(); extern int sync_timeout_in_ms; void sync_main_handler(); bluetooth::common::MessageLoopThread* get_main_thread(); bool is_on_main_thread(); Loading
system/stack/btu/btu_task.cc +19 −0 Original line number Diff line number Diff line Loading @@ -126,3 +126,22 @@ void main_thread_start_up() { } void main_thread_shut_down() { main_thread.ShutDown(); } bool is_on_main_thread() { // Pthreads doesn't have the concept of a thread ID, so we have to reach down // into the kernel. #if defined(OS_MACOSX) return main_thread.GetThreadId() == pthread_mach_thread_np(pthread_self()); #elif defined(OS_LINUX) #include <sys/syscall.h> /* For SYS_xxx definitions */ #include <unistd.h> return main_thread.GetThreadId() == syscall(__NR_gettid); #elif defined(OS_ANDROID) #include <sys/types.h> #include <unistd.h> return main_thread.GetThreadId() == gettid(); #else LOG(ERROR) << __func__ << "Unable to determine if on main thread"; return true; #endif }
system/stack/include/btu.h +1 −0 Original line number Diff line number Diff line Loading @@ -59,6 +59,7 @@ bt_status_t do_in_main_thread_delayed(const base::Location& from_here, base::OnceClosure task, const base::TimeDelta& delay); bool is_on_main_thread(); using BtMainClosure = std::function<void()>; void post_on_bt_main(BtMainClosure closure); Loading
system/test/common/main_handler.cc +21 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ #include <base/callback_forward.h> #include <base/location.h> #include <base/time/time.h> #include <sys/types.h> #include <unistd.h> #include <functional> #include <future> Loading Loading @@ -75,3 +77,22 @@ void sync_main_handler() { post_on_bt_main([&promise]() { promise.set_value(); }); future.wait_for(std::chrono::milliseconds(sync_timeout_in_ms)); }; bool is_on_main_thread() { // Pthreads doesn't have the concept of a thread ID, so we have to reach down // into the kernel. #if defined(OS_MACOSX) return main_thread.GetThreadId() == pthread_mach_thread_np(pthread_self()); #elif defined(OS_LINUX) #include <sys/syscall.h> /* For SYS_xxx definitions */ #include <unistd.h> return main_thread.GetThreadId() == syscall(__NR_gettid); #elif defined(OS_ANDROID) #include <sys/types.h> #include <unistd.h> return main_thread.GetThreadId() == gettid(); #else LOG(ERROR) << __func__ << "Unable to determine if on main thread"; return true; #endif }
system/test/common/main_handler.h +1 −0 Original line number Diff line number Diff line Loading @@ -37,3 +37,4 @@ void main_thread_shut_down(); extern int sync_timeout_in_ms; void sync_main_handler(); bluetooth::common::MessageLoopThread* get_main_thread(); bool is_on_main_thread();