Skip to content

Add option to force single core decoding #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 27, 2025
Merged
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
21 changes: 13 additions & 8 deletions src/OpenStreetMap-esp32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ OpenStreetMap::~OpenStreetMap()
{
if (jobQueue && tasksStarted)
{
const int numCores = ESP.getChipCores();
for (int i = 0; i < numCores; ++i)
for (int i = 0; i < numberOfWorkers; ++i)
{
TileJob poison = {};
poison.z = 255;
if (xQueueSend(jobQueue, &poison, portMAX_DELAY) != pdPASS)
log_e("Failed to send poison pill to tile worker %d", i);
}

for (int i = 0; i < numCores; ++i)
for (int i = 0; i < numberOfWorkers; ++i)
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);

tasksStarted = false;
numberOfWorkers = 0;

vQueueDelete(jobQueue);
jobQueue = nullptr;
Expand Down Expand Up @@ -535,14 +535,19 @@ bool OpenStreetMap::startTileWorkerTasks()
return true;

ownerTask = xTaskGetCurrentTaskHandle();

const int numCores = ESP.getChipCores();
for (int core = 0; core < numCores; ++core)
if (!xTaskCreatePinnedToCore(tileFetcherTask, nullptr, OSM_TASK_STACKSIZE, this, OSM_TASK_PRIORITY, nullptr, core))
numberOfWorkers = OSM_FORCE_SINGLECORE ? 1 : ESP.getChipCores();
for (int core = 0; core < numberOfWorkers; ++core)
if (!xTaskCreatePinnedToCore(tileFetcherTask,
nullptr,
OSM_TASK_STACKSIZE,
this,
OSM_TASK_PRIORITY,
nullptr,
OSM_FORCE_SINGLECORE ? OSM_SINGLECORE_NUMBER : core))
return false;

tasksStarted = true;

log_i("Started %d tile worker task(s)", numCores);
log_i("Started %d tile worker task(s)", numberOfWorkers);
return true;
}
7 changes: 6 additions & 1 deletion src/OpenStreetMap-esp32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ constexpr uint16_t OSM_MAX_ZOOM = 18;
constexpr UBaseType_t OSM_TASK_PRIORITY = 10;
constexpr uint32_t OSM_TASK_STACKSIZE = 5120;
constexpr uint32_t OSM_JOB_QUEUE_SIZE = 50;
constexpr bool OSM_FORCE_SINGLECORE = false;
constexpr int OSM_SINGLECORE_NUMBER = 1;

static_assert(OSM_SINGLECORE_NUMBER < 2, "OSM_SINGLECORE_NUMBER must be 0 or 1 (ESP32 has only 2 cores)");

using tileList = std::vector<std::pair<uint32_t, int32_t>>;

Expand Down Expand Up @@ -92,7 +96,7 @@ class OpenStreetMap
double lat2tile(double lat, uint8_t zoom);
void computeRequiredTiles(double longitude, double latitude, uint8_t zoom, tileList &requiredTiles);
void updateCache(const tileList &requiredTiles, uint8_t zoom);
void makeJobList(const tileList &requiredTiles, std::vector<TileJob> &jobs, uint8_t zoom);
void makeJobList(const tileList &requiredTiles, std::vector<TileJob> &jobs, uint8_t zoom);
void runJobs(const std::vector<TileJob> &jobs);
CachedTile *findUnusedTile(const tileList &requiredTiles, uint8_t zoom);
bool isTileCachedOrBusy(uint32_t x, uint32_t y, uint8_t z);
Expand All @@ -104,6 +108,7 @@ class OpenStreetMap
TaskHandle_t ownerTask = nullptr;
bool startTileWorkerTasks();

int numberOfWorkers = 0;
QueueHandle_t jobQueue = nullptr;
std::atomic<int> pendingJobs = 0;
bool tasksStarted = false;
Expand Down