Created
April 13, 2011 03:17
-
-
Save markmarch/916900 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int add_count(unsigned long delta) | |
| { | |
| int c; | |
| int cm; | |
| int old; | |
| int new; | |
| do { | |
| split_counterandmax(&counterandmax, &old, &c, &cm); | |
| if (delta > MAX_COUNTERMAX || c + delta > cm) | |
| goto slowpath; | |
| new = merge_counterandmax(c + delta, cm); | |
| } while (atomic_cmpxchg(&counterandmax, old, new) != old); | |
| return 1; | |
| slowpath: | |
| spin_lock(&gblcnt_mutex); | |
| globalize_count(); | |
| if (globalcountmax - globalcount - globalreserve < delta) { | |
| flush_local_count(); | |
| if (globalcountmax - globalcount - globalreserve < delta) { | |
| spin_unlock(&gblcnt_mutex); | |
| return 0; | |
| } | |
| } | |
| globalcount += delta; | |
| balance_count(); | |
| spin_unlock(&gblcnt_mutex); | |
| return 1; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment