1 /* reserve.c - job reservations */
7 static unsigned int cur_reserved_ct
= 0;
9 /* Doubly-linked list of connections with at least one reserved job. */
10 static struct conn running
= { &running
, &running
, 0 };
13 reserve_job(conn c
, job j
)
15 j
->deadline
= time(NULL
) + RESERVATION_TIMEOUT
;
16 cur_reserved_ct
++; /* stats */
17 conn_insert(&running
, c
);
18 j
->state
= JOB_STATE_RESERVED
;
19 job_insert(&c
->reserved_jobs
, j
);
20 return reply_job(c
, j
, MSG_RESERVED
);
24 has_reserved_job(conn c
)
26 return job_list_any_p(&c
->reserved_jobs
);
29 /* return the reserved job with the earliest deadline,
30 * or NULL if there's no reserved job */
34 job j
, soonest
= NULL
;
36 for (j
= c
->reserved_jobs
.next
; j
!= &c
->reserved_jobs
; j
= j
->next
) {
37 if (j
->deadline
<= (soonest
? : j
)->deadline
) soonest
= j
;
43 enqueue_reserved_jobs(conn c
)
48 while (job_list_any_p(&c
->reserved_jobs
)) {
49 j
= job_remove(c
->reserved_jobs
.next
);
50 r
= enqueue_job(j
, 0);
53 if (!job_list_any_p(&c
->reserved_jobs
)) conn_remove(c
);
58 has_reserved_this_job(conn c
, job needle
)
62 for (j
= c
->reserved_jobs
.next
; j
!= &c
->reserved_jobs
; j
= j
->next
) {
63 if (needle
== j
) return 1;
69 find_reserved_job_in_conn(conn c
, unsigned long long int id
)
73 for (j
= c
->reserved_jobs
.next
; j
!= &c
->reserved_jobs
; j
= j
->next
) {
74 if (j
->id
== id
) return j
;
80 remove_reserved_job(conn c
, unsigned long long int id
)
82 return remove_this_reserved_job(c
, find_reserved_job_in_conn(c
, id
));
87 remove_this_reserved_job(conn c
, job j
)
90 if (j
) cur_reserved_ct
--;
91 if (!job_list_any_p(&c
->reserved_jobs
)) conn_remove(c
);
96 find_reserved_job_in_list(conn list
, unsigned long long int id
)
101 for (c
= list
->next
; c
!= list
; c
= c
->next
) {
102 j
= find_reserved_job_in_conn(c
, id
);
109 find_reserved_job(unsigned long long int id
)
111 return find_reserved_job_in_list(&running
, id
);
115 get_reserved_job_ct()
117 return cur_reserved_ct
;