MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / modMessageService

Function modMessageService

xs/platforms/esp/xsHost.c:1041–1109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1039}
1040
1041void modMessageService(xsMachine *the, int maxDelayMS)
1042{
1043 modMessageRecord msg;
1044 uint32_t startTime = modMilliseconds();
1045 uint32_t maxDuration = (uint32_t)maxDelayMS;
1046 unsigned portBASE_TYPE count = uxQueueMessagesWaiting(the->msgQueue);
1047 if (!count) count = 1; // if no messages pending on entry, service no more than 1 (cannot exit immediately - debug queue messages, and caller expects delay to avoid busy wait)
1048
1049#if CONFIG_ESP_TASK_WDT_EN
1050 #ifndef CONFIG_ESP_TASK_WDT_TIMEOUT_S
1051 // The default timeout is 5s, but it can be changed using this CONFIG decl as well as
1052 // dynamically via esp_task_wdt_reconfigure, we assume "worst case" 1s here if it's not
1053 // defined (could actually be set lower dynamically). There is no way to extract the
1054 // current timeout value from esp-idf.
1055 #define CONFIG_ESP_TASK_WDT_TIMEOUT_S (1)
1056 #endif
1057 if (maxDelayMS >= (CONFIG_ESP_TASK_WDT_TIMEOUT_S * 1000)) {
1058 #if CONFIG_ESP_TASK_WDT_TIMEOUT_S <= 1
1059 maxDelayMS = 500;
1060 #else
1061 maxDelayMS = (CONFIG_ESP_TASK_WDT_TIMEOUT_S - 1) * 1000;
1062 #endif
1063 }
1064#endif
1065
1066#ifdef mxDebug
1067 do {
1068 QueueSetMemberHandle_t queue = xQueueSelectFromSet(the->queues, pdMS_TO_TICKS(maxDelayMS));
1069 if (!queue)
1070 break;
1071
1072 if (!xQueueReceive(queue, &msg, 0))
1073 break;
1074
1075 modWatchDogReset();
1076 if (msg.embeddedMessage)
1077 (msg.callback)(the, msg.refcon, (uint8_t *)&msg.message, msg.length);
1078 else {
1079 (msg.callback)(the, msg.refcon, msg.message, msg.length);
1080 if (msg.message)
1081 c_free(msg.message);
1082 }
1083
1084 if ((queue == the->msgQueue) && !--count)
1085 break;
1086 maxDelayMS = 0;
1087 } while ((modMilliseconds() - startTime) < maxDuration);
1088#else
1089 do {
1090 if (!xQueueReceive(the->msgQueue, &msg, pdMS_TO_TICKS(maxDelayMS)))
1091 break;
1092
1093 modWatchDogReset();
1094 if (msg.embeddedMessage)
1095 (msg.callback)(the, msg.refcon, (uint8_t *)&msg.message, msg.length);
1096 else {
1097 (msg.callback)(the, msg.refcon, msg.message, msg.length);
1098 if (msg.message)

Callers 1

workerLoopFunction · 0.50

Calls 1

modMillisecondsFunction · 0.85

Tested by

no test coverage detected