Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0022c7b7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "For `scan_manager_refactor`, wait for the completion of...

Merge "For `scan_manager_refactor`, wait for the completion of `start_up_rust_module_async`." into main
parents cf23fb65 773d3bfb
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@

#include <stdbool.h>

#include <future>

#include "core_callbacks.h"
#include "osi/include/future.h"

@@ -32,7 +34,7 @@ typedef struct {
                               ProfileStopCallback);
  void (*shut_down_stack_async)(ProfileStopCallback);
  void (*clean_up_stack)(ProfileStopCallback);
  void (*start_up_rust_module_async)();
  void (*start_up_rust_module_async)(std::promise<void> promise);
  void (*shut_down_rust_module_async)();

  bool (*get_stack_is_running)(void);
+9 −1
Original line number Diff line number Diff line
@@ -498,7 +498,15 @@ static int disable(void) {

static void cleanup(void) { stack_manager_get_interface()->clean_up_stack(&stop_profiles); }

static void start_rust_module(void) { stack_manager_get_interface()->start_up_rust_module_async(); }
static void start_rust_module(void) {
  std::promise<void> rust_up_promise;
  auto rust_up_future = rust_up_promise.get_future();
  stack_manager_get_interface()->start_up_rust_module_async(std::move(rust_up_promise));
  auto status = rust_up_future.wait_for(std::chrono::milliseconds(1000));
  if (status != std::future_status::ready) {
    log::error("Failed to wait for rust initialization in time. May lead to unpredictable crash");
  }
}

static void stop_rust_module(void) { stack_manager_get_interface()->shut_down_rust_module_async(); }

+6 −4
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ static void event_start_up_stack(bluetooth::core::CoreInterface* interface,
                                 ProfileStopCallback stopProfiles);
static void event_shut_down_stack(ProfileStopCallback stopProfiles);
static void event_clean_up_stack(std::promise<void> promise, ProfileStopCallback stopProfiles);
static void event_start_up_rust_module();
static void event_start_up_rust_module(std::promise<void> promise);
static void event_shut_down_rust_module();

static void event_signal_stack_up(void* context);
@@ -183,8 +183,9 @@ static void clean_up_stack(ProfileStopCallback stopProfiles) {
  }
}

static void start_up_rust_module_async() {
  management_thread.DoInThread(FROM_HERE, base::BindOnce(event_start_up_rust_module));
static void start_up_rust_module_async(std::promise<void> promise) {
  management_thread.DoInThread(FROM_HERE,
                               base::BindOnce(event_start_up_rust_module, std::move(promise)));
}

static void shut_down_rust_module_async() {
@@ -391,9 +392,10 @@ static void event_shut_down_stack(ProfileStopCallback stopProfiles) {
  info("finished");
}

static void event_start_up_rust_module() {
static void event_start_up_rust_module(std::promise<void> promise) {
  info("is bringing up the Rust module");
  module_start_up(get_local_module(RUST_MODULE));
  promise.set_value();
  info("finished");
}

+2 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */

#include <cstdint>
#include <future>

#include "btif/include/stack_manager_t.h"
#include "hardware/bluetooth.h"
@@ -72,7 +73,7 @@ static void shut_down_stack_async(ProfileStopCallback /* stopProfiles */) {}

static void clean_up_stack(ProfileStopCallback /* stopProfiles */) {}

static void start_up_rust_module_async() {}
static void start_up_rust_module_async(std::promise<void> /* promise */) {}

static void shut_down_rust_module_async() {}