You can push overflow processing off onto the readers of a counter, so that
it doesn't hurt performance of the writers of a counter:
writer:
/* assuming 32-bit longs */
unsigned long counter_low; /* low 24 bits */
unsigned long counter_high; /* high 32 bits */
...
++counter_low;
reader:
long long counter_value;
if ( counter_low & 0xFF000000 ) {
counter_high += counter_low >> 24;
counter_low &= 0x00FFFFFF;
}
counter_value = ((long long)counter_high << 24) + counter_low;
This only gives you a 56 bit counter, not a 64 bit counter, and it assumes
that someone reads the counter often enough for the overflow processing to
keep counter_low from overflowing, but that usually can be arranged.
--Tim Smith
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/