test: fix stack bug
authorInki Dae <inki.dae@samsung.com>
Tue, 20 Oct 2020 00:40:05 +0000 (09:40 +0900)
committerInki Dae <inki.dae@samsung.com>
Tue, 20 Oct 2020 00:40:05 +0000 (09:40 +0900)
Change-Id: I6a485fc03a0dee5789918e5f81235a1c54d72964
Signed-off-by: Inki Dae <inki.dae@samsung.com>
test/testsuites/stream_infer/stream_infer.c
test/testsuites/stream_infer/stream_infer_common_util.c
test/testsuites/stream_infer/stream_infer_common_util.h

index 010cfdc88ee70e106563e431f35b836bd31b038f..839b5da6a3ef6a8c271f0385d783a808bda02e0c 100644 (file)
@@ -511,7 +511,6 @@ run_pose (void *user_data)
                user_stack_t *s = PopBuffer();
                if (s == NULL) {
                        g_mutex_unlock(&pose_mutex);
-                       printf("empty\n");
                        usleep(10);
                        continue;
                }
@@ -536,6 +535,7 @@ run_pose (void *user_data)
 
                gst_buffer_unmap((GstBuffer *)s->buffer, &map);
 
+               s->in_use = 0;
                current_data_p = *s;
 
                g_mutex_unlock(&pose_mutex);
@@ -584,6 +584,7 @@ run_hand (void *user_data)
 
                gst_buffer_unmap((GstBuffer *)s->buffer, &map);
 
+               s->in_use = 0;
                current_data_p = *s;
 
                g_mutex_unlock(&pose_mutex);
index 2d8f7be88818b0fce809b03149a8d36462aa78ee..40d8acadc85a98264058cd3314cd15d109bedf1b 100644 (file)
@@ -10,7 +10,7 @@
 #define NANO_PER_MILLI  ((__clock_t) 1000000)
 #define MILLI_PER_SEC  ((__clock_t) 1000)
 #define MAX_MSG_LEN            256
-#define MAX_STACK_SIZE 200 //50
+#define MAX_STACK_SIZE 20
 
 typedef struct {
        char msg[MAX_MSG_LEN];
@@ -77,34 +77,51 @@ void DeinitProfiler(void)
                fclose(gFile);
 }
 
-static user_stack_t FREE_STACK[MAX_STACK_SIZE * 2], *STACK[MAX_STACK_SIZE];
-static int s_cnt, down_s, top_s;
+static user_stack_t FREE_STACK[MAX_STACK_SIZE + 1], *STACK[MAX_STACK_SIZE + 1];
+static int s_cnt, stack_p;
 
 user_stack_t *GetNewStack(void)
 {
-       if (s_cnt == (MAX_STACK_SIZE * 2))
+       if (s_cnt == MAX_STACK_SIZE)
                s_cnt = 0;
 
-       return &FREE_STACK[s_cnt++];
+       while (1) {
+               if (FREE_STACK[s_cnt].in_use == 0) {
+                       return &FREE_STACK[s_cnt++];
+               }
+
+               printf("try to alloc again.(s_cnt in use = %d)\n", s_cnt);
+               s_cnt++;
+
+               for (int i = 0; i < MAX_STACK_SIZE; i++) {
+                       printf("stack idx[%d] : in_use[%d]\n", i, FREE_STACK[i].in_use);
+               }
+
+               if (s_cnt >= MAX_STACK_SIZE)
+                       s_cnt = 0;
+       }
+
+       return NULL;
 }
 
 void PushBuffer(user_stack_t *data)
 {
-       if (top_s == MAX_STACK_SIZE) {
-               top_s = down_s;
+       if (stack_p == MAX_STACK_SIZE) {
+               stack_p = 0;
        }
 
-       STACK[top_s++] = data;
+       STACK[stack_p++] = data;
 }
 
 user_stack_t *PopBuffer(void)
 {
-       if (down_s == top_s) {
-               // there must be no case.
+       if (stack_p == 0) {
+               printf("Stack is empty!!!\n");
                return NULL;
        }
 
-       user_stack_t *data = STACK[--top_s];
+       user_stack_t *data = STACK[--stack_p];
+       data->in_use = 1;
 
        return data;
 }
index 45946af4e466a907094a2a1ff610d9efd323beb5..1f0fcfc0a2cbdec083e490b4476d21f23b57e87b 100644 (file)
@@ -4,6 +4,7 @@ typedef struct STACK {
        void *buffer;
        void *user_data;
        struct timespec s_time;
+       int in_use;
 } user_stack_t;
 
 void InitProfiler(void);