Lines Matching refs:mix

12 static inline struct id_offset *find_unused(const struct buffer_share *mix)  in find_unused()  argument
16 for (i = 0; i < mix->id_sz; i++) { in find_unused()
17 if (!mix->wr_idx[i].used) in find_unused()
18 return &mix->wr_idx[i]; in find_unused()
25 static inline struct id_offset *find_id(const struct buffer_share *mix, in find_id() argument
30 for (i = 0; i < mix->id_sz; i++) { in find_id()
31 if (mix->wr_idx[i].used && id == mix->wr_idx[i].id) in find_id()
32 return &mix->wr_idx[i]; in find_id()
38 static void alloc_more_ids(struct buffer_share *mix) in alloc_more_ids() argument
40 unsigned int new_size = mix->id_sz * 2; in alloc_more_ids()
43 mix->wr_idx = realloc(mix->wr_idx, sizeof(mix->wr_idx[0]) * new_size); in alloc_more_ids()
45 for (i = mix->id_sz; i < new_size; i++) in alloc_more_ids()
46 mix->wr_idx[i].used = 0; in alloc_more_ids()
48 mix->id_sz = new_size; in alloc_more_ids()
53 struct buffer_share *mix; in buffer_share_create() local
55 mix = calloc(1, sizeof(*mix)); in buffer_share_create()
56 mix->id_sz = INITIAL_ID_SIZE; in buffer_share_create()
57 mix->wr_idx = calloc(mix->id_sz, sizeof(mix->wr_idx[0])); in buffer_share_create()
58 mix->buf_sz = buf_sz; in buffer_share_create()
60 return mix; in buffer_share_create()
63 void buffer_share_destroy(struct buffer_share *mix) in buffer_share_destroy() argument
65 if (!mix) in buffer_share_destroy()
67 free(mix->wr_idx); in buffer_share_destroy()
68 free(mix); in buffer_share_destroy()
71 int buffer_share_add_id(struct buffer_share *mix, unsigned int id, void *data) in buffer_share_add_id() argument
75 o = find_id(mix, id); in buffer_share_add_id()
79 o = find_unused(mix); in buffer_share_add_id()
81 alloc_more_ids(mix); in buffer_share_add_id()
83 o = find_unused(mix); in buffer_share_add_id()
92 int buffer_share_rm_id(struct buffer_share *mix, unsigned int id) in buffer_share_rm_id() argument
96 o = find_id(mix, id); in buffer_share_rm_id()
105 int buffer_share_offset_update(struct buffer_share *mix, unsigned int id, in buffer_share_offset_update() argument
110 for (i = 0; i < mix->id_sz; i++) { in buffer_share_offset_update()
111 if (id != mix->wr_idx[i].id) in buffer_share_offset_update()
114 mix->wr_idx[i].offset += delta; in buffer_share_offset_update()
121 unsigned int buffer_share_get_new_write_point(struct buffer_share *mix) in buffer_share_get_new_write_point() argument
123 unsigned int min_written = mix->buf_sz + 1; in buffer_share_get_new_write_point()
126 for (i = 0; i < mix->id_sz; i++) { in buffer_share_get_new_write_point()
127 struct id_offset *o = &mix->wr_idx[i]; in buffer_share_get_new_write_point()
134 for (i = 0; i < mix->id_sz; i++) { in buffer_share_get_new_write_point()
135 struct id_offset *o = &mix->wr_idx[i]; in buffer_share_get_new_write_point()
139 if (min_written > mix->buf_sz) in buffer_share_get_new_write_point()
145 static struct id_offset *get_id_offset(const struct buffer_share *mix, in get_id_offset() argument
151 for (i = 0; i < mix->id_sz; i++) { in get_id_offset()
152 o = &mix->wr_idx[i]; in get_id_offset()
159 unsigned int buffer_share_id_offset(const struct buffer_share *mix, in buffer_share_id_offset() argument
162 struct id_offset *o = get_id_offset(mix, id); in buffer_share_id_offset()
166 void *buffer_share_get_data(const struct buffer_share *mix, in buffer_share_get_data() argument
169 struct id_offset *o = get_id_offset(mix, id); in buffer_share_get_data()