9 #define MAX_NUM_ELEMS (1024 * 1024)
15 #define ALLOC_HEADER_SIZE \
16 ((sizeof(alloc_header) + ABTU_MAX_ALIGNMENT - 1) / ABTU_MAX_ALIGNMENT * \
31 ABTI_CHECK_ERROR(ret);
35 p_header->p_next = NULL;
36 p_header->p_prev = p_alloc_list->
p_tail;
37 if (p_alloc_list->
p_tail) {
39 p_alloc_list->
p_tail = p_header;
41 p_alloc_list->
p_head = p_header;
42 p_alloc_list->
p_tail = p_header;
48 size_t new_size,
void **p_ptr)
62 ABTI_CHECK_ERROR(ret);
66 if (p_alloc_list->
p_head == p_old_header)
67 p_alloc_list->
p_head = p_new_header;
68 if (p_alloc_list->
p_tail == p_old_header)
69 p_alloc_list->
p_tail = p_new_header;
70 p_new_header->
p_prev = p_old_prev_header;
71 if (p_old_prev_header)
72 p_old_prev_header->
p_next = p_new_header;
73 p_new_header->
p_next = p_old_next_header;
74 if (p_old_next_header)
75 p_old_next_header->
p_prev = p_new_header;
91 ABTD_affinity_id_list **pp_id_list)
93 return list_calloc(p_alloc_list,
sizeof(ABTD_affinity_id_list),
98 ABTD_affinity_id_list *p_id_list,
int id,
99 uint32_t num,
int stride)
103 int ret =
list_realloc(p_alloc_list,
sizeof(
int) * p_id_list->num,
104 sizeof(
int) * (p_id_list->num + num),
105 (
void **)&p_id_list->ids);
106 ABTI_CHECK_ERROR(ret);
107 for (i = 0; i < num; i++) {
108 p_id_list->ids[p_id_list->num + i] =
id + stride * i;
110 p_id_list->num += num;
115 ABTD_affinity_list **pp_affinity_list)
117 return list_calloc(p_alloc_list,
sizeof(ABTD_affinity_list),
118 (
void **)pp_affinity_list);
122 ABTD_affinity_list *p_list,
123 ABTD_affinity_id_list *p_base, uint32_t num,
131 sizeof(ABTD_affinity_id_list *) * p_list->num,
132 sizeof(ABTD_affinity_id_list *) * (p_list->num + num),
133 (
void **)&p_list->p_id_lists);
134 ABTI_CHECK_ERROR(ret);
135 for (i = 1; i < num; i++) {
136 ABTD_affinity_id_list *p_id_list;
138 ABTI_CHECK_ERROR(ret);
139 p_id_list->num = p_base->num;
140 ret =
list_calloc(p_alloc_list,
sizeof(
int) * p_id_list->num,
141 (
void **)&p_id_list->ids);
142 ABTI_CHECK_ERROR(ret);
143 for (j = 0; j < p_id_list->num; j++)
144 p_id_list->ids[j] = p_base->ids[j] + stride * i;
145 p_list->p_id_lists[p_list->num + i] = p_id_list;
147 p_list->p_id_lists[p_list->num] = p_base;
154 return c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n';
158 static int consume_int(
const char *str, uint32_t *p_index,
int *p_val)
160 uint32_t index = *p_index;
161 int val = 0, val_sign = 1;
164 char c = *(str + index);
165 if (flag !=
'v' && c ==
'-') {
168 val_sign = -val_sign;
169 }
else if (flag !=
'v' && c ==
'+') {
174 }
else if (
'0' <= c && c <=
'9') {
177 val = val * 10 + (int)(c -
'0');
182 *p_val = val * val_sign;
195 static int consume_pint(
const char *str, uint32_t *p_index,
int *p_val)
197 uint32_t index = *p_index;
211 uint32_t index = *p_index;
213 char c = *(str + index);
215 *p_index = index + 1;
229 uint32_t *p_index, ABTD_affinity_id_list **pp_affinity_id_list)
232 ABTD_affinity_id_list *p_affinity_id_list;
234 ABTI_CHECK_ERROR(ret);
238 ret =
id_list_add(p_alloc_list, p_affinity_id_list, val, 1, 1);
239 ABTI_CHECK_ERROR(ret);
240 *pp_affinity_id_list = p_affinity_id_list;
245 int id, num = 1, stride = 1;
265 id_list_add(p_alloc_list, p_affinity_id_list,
id, num, stride);
266 ABTI_CHECK_ERROR(ret);
277 *pp_affinity_id_list = p_affinity_id_list;
285 const char *affinity_str,
286 ABTD_affinity_list **pp_affinity_list)
292 ABTD_affinity_list *p_affinity_list;
294 ABTI_CHECK_ERROR(ret);
296 ABTD_affinity_id_list *p_id_list = NULL;
298 int num = 1, stride = 1;
302 ABTI_CHECK_ERROR(ret);
318 ret =
list_add(p_alloc_list, p_affinity_list, p_id_list, num, stride);
319 ABTI_CHECK_ERROR(ret);
330 *pp_affinity_list = p_affinity_list;
337 ABTD_affinity_list_create(
const char *affinity_str,
338 ABTD_affinity_list **pp_affinity_list)
340 ABTD_affinity_list *p_affinity_list;
342 int ret =
parse_list(&tmp_alloc_list, affinity_str, &p_affinity_list);
350 p_affinity_list->p_mem_head = (
void *)tmp_alloc_list.
p_head;
351 *pp_affinity_list = p_affinity_list;
356 void ABTD_affinity_list_free(ABTD_affinity_list *p_affinity_list)
358 if (p_affinity_list) {
365 static int is_equal(
const ABTD_affinity_list *a,
const ABTD_affinity_list *b)
368 if (a->num != b->num)
370 for (i = 0; i < a->num; i++) {
371 const ABTD_affinity_id_list *a_id = a->p_id_lists[i];
372 const ABTD_affinity_id_list *b_id = b->p_id_lists[i];
373 if (a_id->num != b_id->num)
375 for (j = 0; j < a_id->num; j++) {
376 if (a_id->ids[j] != b_id->ids[j])
383 static int is_equal_str(
const char *a_str,
const char *b_str)
386 ABTD_affinity_list *a, *b;
389 int ret1 =
parse_list(&tmp_alloc_list1, a_str, &a);
390 int ret2 =
parse_list(&tmp_alloc_list2, b_str, &b);
397 static int is_err_str(
const char *str)
400 ABTD_affinity_list *a;
401 int ret =
parse_list(&tmp_alloc_list, str, &a);
409 static void test_parse(
void)
412 assert(!is_err_str(
"++1"));
413 assert(!is_err_str(
"+-1"));
414 assert(!is_err_str(
"+-+-1"));
415 assert(!is_err_str(
"+0"));
416 assert(!is_err_str(
"-0"));
417 assert(!is_err_str(
"-9:1:-9"));
418 assert(!is_err_str(
"-9:1:0"));
419 assert(!is_err_str(
"-9:1:9"));
420 assert(!is_err_str(
"0:1:-9"));
421 assert(!is_err_str(
"0:1:0"));
422 assert(!is_err_str(
"0:1:9"));
423 assert(!is_err_str(
"9:1:-9"));
424 assert(!is_err_str(
"9:1:0"));
425 assert(!is_err_str(
"9:1:9"));
426 assert(!is_err_str(
"{-9:1:-9}"));
427 assert(!is_err_str(
"{-9:1:0}"));
428 assert(!is_err_str(
"{-9:1:9}"));
429 assert(!is_err_str(
"{0:1:-9}"));
430 assert(!is_err_str(
"{0:1:0}"));
431 assert(!is_err_str(
"{0:1:9}"));
432 assert(!is_err_str(
"{9:1:-9}"));
433 assert(!is_err_str(
"{9:1:0}"));
434 assert(!is_err_str(
"{9:1:9}"));
435 assert(!is_err_str(
"1,2,3"));
436 assert(!is_err_str(
"1,2,{1,2}"));
437 assert(!is_err_str(
"1,2,{1:2}"));
438 assert(!is_err_str(
"1:2,{1:2}"));
439 assert(!is_err_str(
"1:2:1,2"));
440 assert(!is_err_str(
" 1 : +2 , { -1 : \r 2\n:2}\n"));
442 assert(is_err_str(
""));
443 assert(is_err_str(
"{}"));
444 assert(is_err_str(
"+ 1"));
445 assert(is_err_str(
"+ +1"));
446 assert(is_err_str(
"+ -1"));
447 assert(is_err_str(
"1:"));
448 assert(is_err_str(
"1:2:"));
449 assert(is_err_str(
"1:2,"));
450 assert(is_err_str(
"1:-2"));
451 assert(is_err_str(
"1:0"));
452 assert(is_err_str(
"1:-2:4"));
453 assert(is_err_str(
"1:0:4"));
454 assert(is_err_str(
"1:1:1:"));
455 assert(is_err_str(
"1:1:1:1"));
456 assert(is_err_str(
"1:1:1:1,1"));
457 assert(is_err_str(
"{1:2:3},"));
458 assert(is_err_str(
"{1:2:3}:"));
459 assert(is_err_str(
"{1:2:3}:2:"));
460 assert(is_err_str(
"{:2:3}"));
461 assert(is_err_str(
"{{2:3}}"));
462 assert(is_err_str(
"{2:3}}"));
463 assert(is_err_str(
"2:3}"));
464 assert(is_err_str(
"{1:2:3"));
465 assert(is_err_str(
"{1,2,}"));
466 assert(is_err_str(
"{1:-2}"));
467 assert(is_err_str(
"{1:0}"));
468 assert(is_err_str(
"{1:-2:4}"));
469 assert(is_err_str(
"{1:0:4}"));
471 assert(is_equal_str(
"{1},{2},{3},{4}",
"1,2,3,4"));
472 assert(is_equal_str(
"{1:4:1}",
"{1,2,3,4}"));
473 assert(is_equal_str(
"{1:4}",
"{1,2,3,4}"));
474 assert(is_equal_str(
"1:2,3:2",
"1,2,3,4"));
475 assert(is_equal_str(
"{1:2},3:2",
"{1,2},3,4"));
476 assert(is_equal_str(
"{1:1:4},{2:1:-4},{3:1:0},{4:1}",
"1,2,3,4"));
477 assert(is_equal_str(
"{3:4:-1}",
"{3,2,1,0}"));
478 assert(is_equal_str(
"3:4:-1,-1",
"3,2,1,0,-1"));
479 assert(is_equal_str(
"{1:2:3}:1",
"{1,4}"));
480 assert(is_equal_str(
"{1:2:3}:3",
"{1,4},{2,5},{3,6}"));
481 assert(is_equal_str(
"{1:2:3}:3:2",
"{1,4},{3,6},{5,8}"));
482 assert(is_equal_str(
"{1:2:3}:3:-2",
"{1,4},{-1,2},{-3,0}"));
483 assert(is_equal_str(
"{1:2:3}:3:-2,1",
"{1,4},{-1,2},{-3,0},1"));
484 assert(is_equal_str(
"{-2:3:-2}:2:-4",
"{-2,-4,-6},{-6,-8,-10}"));