Lines Matching +full:cs +full:- +full:1
1 // SPDX-License-Identifier: GPL-2.0
24 static void comm_strs__remove_if_last(struct comm_str *cs);
43 static refcount_t *comm_str__refcnt(struct comm_str *cs) in comm_str__refcnt() argument
45 return &RC_CHK_ACCESS(cs)->refcnt; in comm_str__refcnt()
48 static const char *comm_str__str(const struct comm_str *cs) in comm_str__str() argument
50 return &RC_CHK_ACCESS(cs)->str[0]; in comm_str__str()
53 static struct comm_str *comm_str__get(struct comm_str *cs) in comm_str__get() argument
57 if (RC_CHK_GET(result, cs)) in comm_str__get()
58 refcount_inc_not_zero(comm_str__refcnt(cs)); in comm_str__get()
63 static void comm_str__put(struct comm_str *cs) in comm_str__put() argument
65 if (!cs) in comm_str__put()
68 if (refcount_dec_and_test(comm_str__refcnt(cs))) { in comm_str__put()
69 RC_CHK_FREE(cs); in comm_str__put()
71 if (refcount_read(comm_str__refcnt(cs)) == 1) in comm_str__put()
72 comm_strs__remove_if_last(cs); in comm_str__put()
74 RC_CHK_PUT(cs); in comm_str__put()
81 RC_STRUCT(comm_str) *cs; in comm_str__new()
83 cs = malloc(sizeof(*cs) + strlen(str) + 1); in comm_str__new()
84 if (ADD_RC_CHK(result, cs)) { in comm_str__new()
85 refcount_set(comm_str__refcnt(result), 1); in comm_str__new()
86 strcpy(&cs->str[0], str); in comm_str__new()
99 static void comm_strs__remove_if_last(struct comm_str *cs) in comm_strs__remove_if_last() argument
103 down_write(&comm_strs->lock); in comm_strs__remove_if_last()
108 if (refcount_read(comm_str__refcnt(cs)) == 1) { in comm_strs__remove_if_last()
111 entry = bsearch(comm_str__str(cs), comm_strs->strs, comm_strs->num_strs, in comm_strs__remove_if_last()
114 for (int i = entry - comm_strs->strs; i < comm_strs->num_strs - 1; i++) in comm_strs__remove_if_last()
115 comm_strs->strs[i] = comm_strs->strs[i + 1]; in comm_strs__remove_if_last()
116 comm_strs->num_strs--; in comm_strs__remove_if_last()
118 up_write(&comm_strs->lock); in comm_strs__remove_if_last()
125 result = bsearch(str, comm_strs->strs, comm_strs->num_strs, sizeof(struct comm_str *), in __comm_strs__find()
142 down_read(&comm_strs->lock); in comm_strs__findnew()
144 up_read(&comm_strs->lock); in comm_strs__findnew()
148 down_write(&comm_strs->lock); in comm_strs__findnew()
151 if (comm_strs->num_strs == comm_strs->capacity) { in comm_strs__findnew()
154 tmp = reallocarray(comm_strs->strs, in comm_strs__findnew()
155 comm_strs->capacity + 16, in comm_strs__findnew()
156 sizeof(*comm_strs->strs)); in comm_strs__findnew()
158 up_write(&comm_strs->lock); in comm_strs__findnew()
161 comm_strs->strs = tmp; in comm_strs__findnew()
162 comm_strs->capacity += 16; in comm_strs__findnew()
166 int low = 0, high = comm_strs->num_strs - 1; in comm_strs__findnew()
167 int insert = comm_strs->num_strs; /* Default to inserting at the end. */ in comm_strs__findnew()
170 int mid = low + (high - low) / 2; in comm_strs__findnew()
171 int cmp = strcmp(comm_str__str(comm_strs->strs[mid]), str); in comm_strs__findnew()
174 low = mid + 1; in comm_strs__findnew()
176 high = mid - 1; in comm_strs__findnew()
180 memmove(&comm_strs->strs[insert + 1], &comm_strs->strs[insert], in comm_strs__findnew()
181 (comm_strs->num_strs - insert) * sizeof(struct comm_str *)); in comm_strs__findnew()
182 comm_strs->num_strs++; in comm_strs__findnew()
183 comm_strs->strs[insert] = result; in comm_strs__findnew()
186 up_write(&comm_strs->lock); in comm_strs__findnew()
197 comm->start = timestamp; in comm__new()
198 comm->exec = exec; in comm__new()
200 comm->comm_str = comm_strs__findnew(str); in comm__new()
201 if (!comm->comm_str) { in comm__new()
211 struct comm_str *new, *old = comm->comm_str; in comm__override()
215 return -ENOMEM; in comm__override()
218 comm->comm_str = new; in comm__override()
219 comm->start = timestamp; in comm__override()
221 comm->exec = true; in comm__override()
228 comm_str__put(comm->comm_str); in comm__free()
234 return comm_str__str(comm->comm_str); in comm__str()