72#if defined (BINARY_LEASES)
76#define LC_GROWTH_DELTA 256
88#if defined (DEBUG_BINARY_LEASES)
93 return (lc->
nelem > 0 ? 1 : 0);
106#if defined (DEBUG_BINARY_LEASES)
129#if defined (DEBUG_BINARY_LEASES)
156 size_t min,
size_t max)
158 size_t mid_index = ((max - min)/2) + min;
163 if (mid_index == min) {
168 return (lc_binary_search_insert_point(
lc, lp,
169 min, mid_index - 1));
173 if (mid_index == max) {
175 return (mid_index+1);
178 return (lc_binary_search_insert_point(
lc, lp,
179 mid_index + 1, max));
205 size_t min,
size_t max)
215 mid_index = ((max - min)/2) + min;
220 if (mid_index == min) {
225 return (lc_binary_search_lease(
lc, lp, min, mid_index - 1));
230 return (lc_binary_search_lease(
lc, lp, mid_index + 1, max));
239 if (lp ==
lc->
list[mid_index]) {
244 if (mid_index > min) {
249 for (i = mid_index - 1; ; i--) {
265 if (mid_index < max) {
269 for (i = mid_index + 1; i <= max; i++) {
300#if defined (DEBUG_BINARY_LEASES)
308 temp_size =
lc->
total + LC_GROWTH_DELTA;
315 log_fatal(
"LC grow, unable to allocated memory %s:%d",
MDL);
344#if defined (DEBUG_BINARY_LEASES)
354#if defined (DEBUG_BINARY_LEASES)
355 log_debug(
"LC Link lcp position %zu, elem %zu, %s:%d",
361#if defined (DEBUG_BINARY_LEASES)
362 log_debug(
"LC link lcp moving position %zu, moving %zu. %s:%d",
373 lease_reference(&(
lc->
list[n]), lp,
MDL);
396#if defined (DEBUG_BINARY_LEASES)
397 log_debug(
"LC Add lease position %zu, %s:%d", pos,
MDL);
401 lc_link_lcp(
lc, lp, pos);
408 lease_dereference(&lp->
prev,
MDL);
411 lease_dereference(&lp->
next,
MDL);
450 long int tiebreak = 0;
453 for (i = 0; i <
lc->
nelem; i++ ) {
456 (
lc->
list[i]->tiebreaker < tiebreaker))) {
461 if (i < lc->nelem - 1) {
500#if defined (DEBUG_BINARY_LEASES)
510 lc_add_lease_pos(
lc, lp, 0);
531 pos = lc_binary_search_insert_point(
lc, lp, 0,
lc->
nelem - 1);
535 lc_add_lease_pos(
lc, lp, pos);
537#if defined (DEBUG_BINARY_LEASES)
538 log_debug(
"LC add sorted complete position %zu, elements %zu, %s:%d",
543 lc_check_lc_sort_order(
lc);
557#if defined (DEBUG_BINARY_LEASES)
561 INSIST(n < lc->nelem);
589#if defined (DEBUG_BINARY_LEASES)
593 struct lease *lp = NULL;
594 lease_reference(&lp,
lc->
list[pos],
MDL);
597 lc_unlink_lcp(
lc, pos);
609 lease_dereference(&lp->
prev,
MDL);
612 lease_dereference(&lp->
next,
MDL);
614 lease_dereference(&lp,
MDL);
627#if defined (DEBUG_BINARY_LEASES)
633 INSIST(lp->
lc != NULL );
634 INSIST(lp->
lc ==
lc );
637 size_t pos = lc_binary_search_lease(
lc, lp, 0,
lc->
nelem-1);
638 if (pos == SIZE_MAX) {
640 log_fatal(
"Lease with binding state %s not on its queue.",
647 lc_unlink_lease_pos(
lc, pos);
664 for (i =
lc->
nelem - 1; ; i--) {
665 lc_unlink_lease_pos(
lc, i);
void print_lease(struct lease *lease)
struct lease * lc_get_first_lease(struct leasechain *lc)
void lc_add_sorted_lease(struct leasechain *lc, struct lease *lp)
void lc_delete_all(struct leasechain *lc)
struct lease * lc_get_next(struct leasechain *lc, struct lease *lp)
void lc_init_growth(struct leasechain *lc, size_t growth)
void lc_unlink_lease(struct leasechain *lc, struct lease *lp)
const char * binding_state_names[]
int lc_not_empty(struct leasechain *lc)
void * dmalloc(size_t, const char *, int)
void dfree(void *, const char *, int)
int int int log_debug(const char *,...) __attribute__((__format__(__printf__
void log_fatal(const char *,...) __attribute__((__format__(__printf__
binding_state_t binding_state