Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.ccache
.idea/
.vscode/
cache.sqlite
cache*.sqlite*
debug/
out.png
target/
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ metal = [] # default on Apple platforms, do not add to default features
opengl = []
vulkan = [] # default on other platforms
log = ["dep:log"]
pool = ["dep:tokio"]
pool = ["dep:tokio", "tokio/rt", "tokio/time", "tokio/rt-multi-thread"]

[dependencies]
cxx.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion include/map_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class MapRenderer {
public:
explicit MapRenderer(std::unique_ptr<mbgl::HeadlessFrontend> frontendInstance,
std::unique_ptr<mbgl::Map> mapInstance)
: frontend(std::move(frontendInstance)),
: runLoop(mbgl::util::RunLoop::Type::Default),
frontend(std::move(frontendInstance)),
map(std::move(mapInstance)) {}
~MapRenderer() {}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ pub use renderer::*;
#[cfg(feature = "pool")]
mod pool;
#[cfg(feature = "pool")]
pub use pool::{SingleThreadedRenderPool, SingleThreadedRenderPoolError};
pub use pool::*;
2 changes: 2 additions & 0 deletions src/pool/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod single_threaded;
pub use single_threaded::*;
File renamed without changes.
60 changes: 60 additions & 0 deletions tests/simple_concurrent_test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use log::{debug, info, warn};
use maplibre_native::ImageRendererOptions;
use std::path::PathBuf;
use std::sync::Arc;
use std::sync::Barrier;
use std::thread;

fn fixture_path(name: &str) -> PathBuf {
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
path.push("tests");
path.push("fixtures");
path.push(name);
assert!(path.is_file());
path
}

#[test]
fn simple_two_thread_concurrent_rendering() {
env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("trace")).init();
let style_paths = vec![
fixture_path("test-style.json"),
fixture_path("test-style-alt.json"),
];

let thread_count = 10;
info!("Starting simple {thread_count}-thread concurrent test");

let mut handles = Vec::new();
let rendering_barrier = Arc::new(Barrier::new(thread_count));
for i in 0..thread_count {
let style_path = style_paths[i % style_paths.len()].clone();
let rendering_barrier = rendering_barrier.clone();
handles.push(thread::spawn(move || {
info!("Thread {i}: Creating renderer");

let mut renderer = ImageRendererOptions::default();
renderer.with_cache_path(format!("cache{i}.sqlite"));
let mut renderer = renderer.build_tile_renderer();

debug!("Thread {i}: Loading style");
if let Err(e) = renderer.load_style_from_path(&style_path) {
panic!("Thread {i}: Failed to load style: {e}");
}

debug!("Thread {i}: Rendering tiles");
rendering_barrier.wait();
for j in 1_u32..1000 {
log::trace!("Thread {i}: Rendering tile {j}");
renderer.render_tile(10, j, 384).unwrap();
}
}));
}

for handle in handles {
handle.join().expect("Thread should not panic");
warn!("Joined thread");
}

info!("Both threads completed successfully!");
}
Loading