Spinlock save cpu flags
This commit is contained in:
@@ -27,26 +27,30 @@ void id_alloc_fini (struct id_alloc* ida) {
|
||||
}
|
||||
|
||||
int id_alloc (struct id_alloc* ida) {
|
||||
spin_lock (&ida->lock);
|
||||
uint64_t fid;
|
||||
|
||||
spin_lock (&ida->lock, &fid);
|
||||
|
||||
for (size_t bit = 0; bit < ida->bm.nbits; bit++) {
|
||||
if (!bm_test (&ida->bm, bit)) {
|
||||
bm_set (&ida->bm, bit);
|
||||
|
||||
spin_unlock (&ida->lock);
|
||||
spin_unlock (&ida->lock, fid);
|
||||
return (int)bit;
|
||||
}
|
||||
}
|
||||
|
||||
spin_unlock (&ida->lock);
|
||||
spin_unlock (&ida->lock, fid);
|
||||
return -ST_OOM_ERROR;
|
||||
}
|
||||
|
||||
void id_free (struct id_alloc* ida, int id) {
|
||||
uint64_t fid;
|
||||
|
||||
if (id < 0)
|
||||
return;
|
||||
|
||||
spin_lock (&ida->lock);
|
||||
spin_lock (&ida->lock, &fid);
|
||||
bm_clear (&ida->bm, (size_t)id);
|
||||
spin_unlock (&ida->lock);
|
||||
spin_unlock (&ida->lock, fid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user