Browse Source

1、modbus从机内存映射初始化位置有误,后移
2、增加线程栈设置容错及获取栈大小接口

guohui 2 years ago
parent
commit
f31ab788f4
3 changed files with 58 additions and 21 deletions
  1. 20 18
      pro/src/app.c
  2. 36 3
      pro/src/thread.c
  3. 2 0
      pro/src/thread.h

+ 20 - 18
pro/src/app.c

@@ -1199,6 +1199,26 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
     //使用的通道
     _globalDeviceManager->useSlaveCount = 0 ;
     
+    //链接数据库获取配置信息
+    sys_get_path(path, DATABASE_NAME);
+    log_i("database: %s\n", path);
+    ret = sqlite_init(&_globalDeviceManager->db,&_globalDeviceManager->dbThreadlock, path);
+    if(ret<0)
+    {
+        log_e("database %s open error.\n", path);
+        return -1 ;
+    }
+    log_i("database %s open ok.\n", path);
+
+    //查询设备总体参数
+    if(dev_get_device_info(_globalDeviceManager->db,_globalDeviceManager->_global_device_info)!=0)
+    {
+        log_e("get device info error.\n");
+        return -1 ;
+    }
+    log_i("get device info ok.\n");
+
+
     if(_globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_AC ||
         _globalDeviceManager->_global_device_info->product_pwr_type == SmartPDU_DC)       // single AC
     {
@@ -1221,24 +1241,6 @@ int _global_device_manage_init(GlobalDeviceManager* _globalDeviceManager)
         }  
         memset(_globalDeviceManager->triphasic_mmap, 0, sizeof(cascade_triphasic_mmap_t));
     }
-    //链接数据库获取配置信息
-    sys_get_path(path, DATABASE_NAME);
-    log_i("database: %s\n", path);
-    ret = sqlite_init(&_globalDeviceManager->db,&_globalDeviceManager->dbThreadlock, path);
-    if(ret<0)
-    {
-        log_e("database %s open error.\n", path);
-        return -1 ;
-    }
-    log_i("database %s open ok.\n", path);
-
-    //查询设备总体参数
-    if(dev_get_device_info(_globalDeviceManager->db,_globalDeviceManager->_global_device_info)!=0)
-    {
-        log_e("get device info error.\n");
-        return -1 ;
-    }
-    log_i("get device info ok.\n");
 
     //打印参数
     //printf_global_device_info(_globalDeviceManager->_global_device_info);

+ 36 - 3
pro/src/thread.c

@@ -15,10 +15,20 @@ int thread_start(int id, thread_fn fn, void *arg, int stksize, int prio)
 
     h->arg  = arg;
     h->quit = 0;
-    pthread_attr_init(&attr);
-    pthread_attr_setstacksize(&attr, stksize);
+
+    r = pthread_attr_init(&attr);
+    if(r) {
+        printf("____ thread %d attr init failed\n", id);
+        return -1;
+    }
+
+    r = pthread_attr_setstacksize(&attr, stksize);
+    if(r) {
+        printf("____ thread %d attr setstacksize %d failed\n", id, stksize);
+    }
     
     r = pthread_create(&h->tid, &attr, fn, h);
+    pthread_attr_destroy(&attr);
 
     return r;
 }
@@ -68,9 +78,32 @@ int thread_start_simp(thread_fn fn, void *arg, int stksize)
     pthread_attr_init(&attr);
     pthread_attr_setstacksize(&attr, stksize);
     
-    return pthread_create(&tid, &attr, fn, arg);
+    r = pthread_create(&tid, &attr, fn, arg);
+    pthread_attr_destroy(&attr);
+
+    return r;
 }
 
 
+int thread_print_stacksize(void)
+{
+    int r;
+    size_t size;
+    pthread_attr_t attr;
 
+    r = pthread_attr_init(&attr);
+    if(r) {
+        printf("___ print stacksize, attr init failed\n");
+        return -1;
+    }
+    r = pthread_attr_getstacksize(&attr, &size);
+    if(r) {
+        printf("___ print stacksize, attr init failed\n");
+    }
+    else {
+        printf("_____ stacksize: %dMB\n", size/MB);
+    }
+    pthread_attr_destroy(&attr);
+    return r;
+}
 

+ 2 - 0
pro/src/thread.h

@@ -2,6 +2,7 @@
 #define __THREAD_Hx__
 
 #include <pthread.h>
+#include <stdio.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -42,6 +43,7 @@ int thread_stop(int id);
 int thread_stop_all(void);
 
 int thread_start_simp(thread_fn fn, void *arg, int stksize);
+int thread_print_stacksize(void);
 
 #ifdef __cplusplus
 }