user_stack_t *s = PopBuffer();
if (s == NULL) {
g_mutex_unlock(&pose_mutex);
- printf("empty\n");
usleep(10);
continue;
}
gst_buffer_unmap((GstBuffer *)s->buffer, &map);
+ s->in_use = 0;
current_data_p = *s;
g_mutex_unlock(&pose_mutex);
gst_buffer_unmap((GstBuffer *)s->buffer, &map);
+ s->in_use = 0;
current_data_p = *s;
g_mutex_unlock(&pose_mutex);
#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];
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;
}