mirror of
https://github.com/cottongin/cardputerzero-camera.git
synced 2026-11-20 22:34:49 -06:00
fix(app): propagate CZ_TARGET_DEVICE to czcamera_core and keep reap_mutex_ across child_pid_ clear
This commit is contained in:
@@ -67,6 +67,10 @@ if(CZ_ENABLE_LVGL AND lvgl_FOUND)
|
|||||||
target_link_libraries(czcamera_core PUBLIC lvgl::lvgl)
|
target_link_libraries(czcamera_core PUBLIC lvgl::lvgl)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(CZ_TARGET_DEVICE)
|
||||||
|
target_compile_definitions(czcamera_core PUBLIC CZ_TARGET_DEVICE=1)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(CZ_BUILD_APP)
|
if(CZ_BUILD_APP)
|
||||||
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")
|
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp")
|
||||||
message(FATAL_ERROR "CZ_BUILD_APP=ON requires src/main.cpp")
|
message(FATAL_ERROR "CZ_BUILD_APP=ON requires src/main.cpp")
|
||||||
@@ -74,9 +78,7 @@ if(CZ_BUILD_APP)
|
|||||||
add_executable(czcamera src/main.cpp)
|
add_executable(czcamera src/main.cpp)
|
||||||
target_compile_options(czcamera PRIVATE -Wall -Wextra -Wpedantic)
|
target_compile_options(czcamera PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
target_link_libraries(czcamera PRIVATE czcamera_core JPEG::JPEG)
|
target_link_libraries(czcamera PRIVATE czcamera_core JPEG::JPEG)
|
||||||
if(CZ_TARGET_DEVICE)
|
if(NOT CZ_TARGET_DEVICE)
|
||||||
target_compile_definitions(czcamera PRIVATE CZ_TARGET_DEVICE=1)
|
|
||||||
else()
|
|
||||||
find_package(SDL2 REQUIRED)
|
find_package(SDL2 REQUIRED)
|
||||||
target_link_libraries(czcamera PRIVATE SDL2::SDL2)
|
target_link_libraries(czcamera PRIVATE SDL2::SDL2)
|
||||||
endif()
|
endif()
|
||||||
|
|||||||
@@ -1111,8 +1111,9 @@ void SubprocessCameraBackend::stdout_reader_loop(int stdout_fd,
|
|||||||
|
|
||||||
std::string reason = "czcamera-cam stdout closed unexpectedly";
|
std::string reason = "czcamera-cam stdout closed unexpectedly";
|
||||||
bool reaped_in_reader = false;
|
bool reaped_in_reader = false;
|
||||||
|
std::unique_lock<std::mutex> reap_lock(reap_mutex_, std::defer_lock);
|
||||||
if (!was_stopping && pid > 0) {
|
if (!was_stopping && pid > 0) {
|
||||||
std::lock_guard<std::mutex> reap_lock(reap_mutex_);
|
reap_lock.lock();
|
||||||
bool still_ours = false;
|
bool still_ours = false;
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> st_lock(state_mutex_);
|
std::lock_guard<std::mutex> st_lock(state_mutex_);
|
||||||
@@ -1129,6 +1130,8 @@ void SubprocessCameraBackend::stdout_reader_loop(int stdout_fd,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keep reap_lock held while clearing child_pid_ under state_mutex_
|
||||||
|
// (maintains lock order reap_mutex_ -> state_mutex_ matching stop_locked).
|
||||||
std::lock_guard<std::mutex> st_lock(state_mutex_);
|
std::lock_guard<std::mutex> st_lock(state_mutex_);
|
||||||
if (reaped_in_reader && child_pid_ == pid) {
|
if (reaped_in_reader && child_pid_ == pid) {
|
||||||
child_pid_ = -1;
|
child_pid_ = -1;
|
||||||
|
|||||||
@@ -259,6 +259,17 @@ void test_sim_backend_lifecycle() {
|
|||||||
assert(from_env != nullptr);
|
assert(from_env != nullptr);
|
||||||
assert(from_env->status().backend_name == "sim");
|
assert(from_env->status().backend_name == "sim");
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
EnvVarGuard clear_backend("CZCAMERA_BACKEND");
|
||||||
|
EnvVarGuard clear_bin("CZCAMERA_CAM_BIN");
|
||||||
|
auto default_backend = cz::create_camera_backend(false);
|
||||||
|
assert(default_backend != nullptr);
|
||||||
|
#ifdef CZ_TARGET_DEVICE
|
||||||
|
assert(default_backend->status().backend_name == "picamera2-subprocess");
|
||||||
|
#else
|
||||||
|
assert(default_backend->status().backend_name == "sim");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
cz::SimCameraBackend sim;
|
cz::SimCameraBackend sim;
|
||||||
assert(!sim.status().ready);
|
assert(!sim.status().ready);
|
||||||
|
|||||||
Reference in New Issue
Block a user