mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 04:43:10 +00:00
Adopt owning_lock for job_ids
This commit is contained in:
parent
eaf143dd8a
commit
017836cffa
1 changed files with 5 additions and 4 deletions
|
@ -156,11 +156,11 @@ int proc_get_last_status() { return last_status; }
|
||||||
|
|
||||||
// Basic thread safe job IDs. The vector consumed_job_ids has a true value wherever the job ID
|
// Basic thread safe job IDs. The vector consumed_job_ids has a true value wherever the job ID
|
||||||
// corresponding to that slot is in use. The job ID corresponding to slot 0 is 1.
|
// corresponding to that slot is in use. The job ID corresponding to slot 0 is 1.
|
||||||
static pthread_mutex_t job_id_lock = PTHREAD_MUTEX_INITIALIZER;
|
static owning_lock<std::vector<bool>> locked_consumed_job_ids;
|
||||||
static std::vector<bool> consumed_job_ids;
|
|
||||||
|
|
||||||
job_id_t acquire_job_id(void) {
|
job_id_t acquire_job_id(void) {
|
||||||
scoped_lock locker(job_id_lock);
|
auto locker = locked_consumed_job_ids.acquire();
|
||||||
|
std::vector<bool> &consumed_job_ids = locker.value;
|
||||||
|
|
||||||
// Find the index of the first 0 slot.
|
// Find the index of the first 0 slot.
|
||||||
std::vector<bool>::iterator slot =
|
std::vector<bool>::iterator slot =
|
||||||
|
@ -179,7 +179,8 @@ job_id_t acquire_job_id(void) {
|
||||||
|
|
||||||
void release_job_id(job_id_t jid) {
|
void release_job_id(job_id_t jid) {
|
||||||
assert(jid > 0);
|
assert(jid > 0);
|
||||||
scoped_lock locker(job_id_lock);
|
auto locker = locked_consumed_job_ids.acquire();
|
||||||
|
std::vector<bool> &consumed_job_ids = locker.value;
|
||||||
size_t slot = (size_t)(jid - 1), count = consumed_job_ids.size();
|
size_t slot = (size_t)(jid - 1), count = consumed_job_ids.size();
|
||||||
|
|
||||||
// Make sure this slot is within our vector and is currently set to consumed.
|
// Make sure this slot is within our vector and is currently set to consumed.
|
||||||
|
|
Loading…
Reference in a new issue