Modbus: allows modbus thread stack size customization with MODBUS_STACK_SIZE macro.
authorEdouard Tisserant <edouard@beremiz.fr>
Wed, 13 Nov 2024 14:42:34 +0100
changeset 4049 80fc760d4a4a
parent 4048 b3ea419a4d47
child 4051 8816aee01b07
child 4052 4fc7a6c05dab
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
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);