Revision 259d8546b3bee62e1ca8107653d2c45105255ceb authored by alex@thinkpad on 02 September 2017, 20:32:31 UTC, committed by alex@thinkpad on 02 September 2017, 20:32:31 UTC
1 parent 6cc5138
util.c
#include <dryos.h>
#include <property.h>
#include <util.h>
/* helper functions for atomic in-/decrasing variables */
void util_atomic_inc(uint32_t *value)
{
uint32_t old_int = cli();
(*value)++;
sei(old_int);
}
void util_atomic_dec(uint32_t *value)
{
uint32_t old_int = cli();
(*value)--;
sei(old_int);
}
/* simple binary search */
/* crit returns negative if the tested value is too high, positive if too low, 0 if perfect */
int bin_search(int lo, int hi, CritFunc crit)
{
ASSERT(crit);
if (lo >= hi-1) return lo;
int m = (lo+hi)/2;
int c = crit(m);
if (c == 0) return m;
if (c > 0) return bin_search(m, hi, crit);
return bin_search(lo, m, crit);
}
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...