From: Inki Dae Date: Tue, 20 Oct 2020 00:40:05 +0000 (+0900) Subject: test: fix stack bug X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=00ab004a34d994f199f15e6d98fea3d0d3916f87;p=platform%2Fcore%2Fapi%2Fmediavision.git test: fix stack bug Change-Id: I6a485fc03a0dee5789918e5f81235a1c54d72964 Signed-off-by: Inki Dae --- diff --git a/test/testsuites/stream_infer/stream_infer.c b/test/testsuites/stream_infer/stream_infer.c index 010cfdc8..839b5da6 100644 --- a/test/testsuites/stream_infer/stream_infer.c +++ b/test/testsuites/stream_infer/stream_infer.c @@ -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); diff --git a/test/testsuites/stream_infer/stream_infer_common_util.c b/test/testsuites/stream_infer/stream_infer_common_util.c index 2d8f7be8..40d8acad 100644 --- a/test/testsuites/stream_infer/stream_infer_common_util.c +++ b/test/testsuites/stream_infer/stream_infer_common_util.c @@ -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; } diff --git a/test/testsuites/stream_infer/stream_infer_common_util.h b/test/testsuites/stream_infer/stream_infer_common_util.h index 45946af4..1f0fcfc0 100644 --- a/test/testsuites/stream_infer/stream_infer_common_util.h +++ b/test/testsuites/stream_infer/stream_infer_common_util.h @@ -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);