# HG changeset patch # User Edouard Tisserant # Date 1731505354 -3600 # Node ID 80fc760d4a4ae082036d79ec21a06d04469d06f4 # Parent b3ea419a4d474b98f2f516a6b061b8b1df7bd3c8 Modbus: allows modbus thread stack size customization with MODBUS_STACK_SIZE macro. For example, add "-DMODBUS_STACK_SIZE=0x2000" to target CFLAGS to limit stack size to 128kB diff -r b3ea419a4d47 -r 80fc760d4a4a modbus/mb_runtime.c --- a/modbus/mb_runtime.c Wed Oct 16 15:45:15 2024 +0200 +++ b/modbus/mb_runtime.c Wed Nov 13 14:42:34 2024 +0100 @@ -688,6 +688,9 @@ int res = 0; pthread_attr_t attr; res |= pthread_attr_init(&attr); +#ifdef MODBUS_STACK_SIZE + res |= pthread_attr_setstacksize(&attr, MODBUS_STACK_SIZE); +#endif res |= pthread_create(&(client_nodes[index].timer_thread_id), &attr, &__mb_client_timer_thread, (void *)((char *)NULL + index)); if (res != 0) { fprintf(stderr, "Modbus plugin: Error (%%d) starting timer thread for modbus client node %%s\n", res, client_nodes[index].location); @@ -701,6 +704,9 @@ int res = 0; pthread_attr_t attr; res |= pthread_attr_init(&attr); +#ifdef MODBUS_STACK_SIZE + res |= pthread_attr_setstacksize(&attr, MODBUS_STACK_SIZE); +#endif res |= pthread_create(&(client_nodes[index].thread_id), &attr, &__mb_client_thread, (void *)((char *)NULL + index)); if (res != 0) { fprintf(stderr, "Modbus plugin: Error (%%d) starting thread for modbus client node %%s\n", res, client_nodes[index].location); @@ -728,6 +734,9 @@ int res = 0; pthread_attr_t attr; res |= pthread_attr_init(&attr); +#ifdef MODBUS_STACK_SIZE + res |= pthread_attr_setstacksize(&attr, MODBUS_STACK_SIZE); +#endif res |= pthread_create(&(server_nodes[index].thread_id), &attr, &__mb_server_thread, (void *)&(server_nodes[index])); if (res != 0) { fprintf(stderr, "Modbus plugin: Error (%%d) starting modbus server thread for node %%s\n", res, server_nodes[index].location);