MCPcopy Create free account
hub / github.com/F-Stack/f-stack / tid_alloc

Function tid_alloc

freebsd/kern/kern_thread.c:231–255  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229}
230
231static lwpid_t
232tid_alloc(void)
233{
234 static lwpid_t trytid;
235 lwpid_t tid;
236
237 mtx_lock(&tid_lock);
238 /*
239 * It is an invariant that the bitmap is big enough to hold maxthread
240 * IDs. If we got to this point there has to be at least one free.
241 */
242 if (trytid >= maxthread)
243 trytid = 0;
244 bit_ffc_at(tid_bitmap, trytid, maxthread, &tid);
245 if (tid == -1) {
246 KASSERT(trytid != 0, ("unexpectedly ran out of IDs"));
247 trytid = 0;
248 bit_ffc_at(tid_bitmap, trytid, maxthread, &tid);
249 KASSERT(tid != -1, ("unexpectedly ran out of IDs"));
250 }
251 bit_set(tid_bitmap, tid);
252 trytid = tid + 1;
253 mtx_unlock(&tid_lock);
254 return (tid + NO_PID);
255}
256
257static void
258tid_free_locked(lwpid_t rtid)

Callers 2

threadinitFunction · 0.85
thread_allocFunction · 0.85

Calls 4

bit_ffc_atFunction · 0.85
bit_setFunction · 0.85
mtx_lockFunction · 0.70
mtx_unlockFunction · 0.70

Tested by

no test coverage detected