summaryrefslogtreecommitdiff
path: root/src/atomic_ops.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2012-10-03 13:02:13 +0400
committerIvan Maidanski <ivmai@mail.ru>2012-10-03 13:02:13 +0400
commit98a3d509fc1c07a95cd62aed03c1968c7b2f87a3 (patch)
tree2ccb28d4e2fd2bb1de10e95bb49b7eff7aeb242c /src/atomic_ops.c
parent74357409ce5ee215b48f8ac253c6126abea02e12 (diff)
downloadlibatomic_ops-98a3d509fc1c07a95cd62aed03c1968c7b2f87a3.tar.gz
Optimize AO_spin manually to minimize compiler influence on its duration
* src/atomic_ops.c (dummy, AO_spin): Use AO_t instead of deprecated AO_T. * src/atomic_ops_stack.c (AO_spin): Likewise. * src/atomic_ops.c (AO_spin): Define as static (since not needed outside). * src/atomic_ops.c (AO_spin): Optimize code manually to minimize speed dependency on compiler optimization level; add comment. * src/atomic_ops_stack.c (AO_spin): Likewise.
Diffstat (limited to 'src/atomic_ops.c')
-rw-r--r--src/atomic_ops.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/atomic_ops.c b/src/atomic_ops.c
index da45eb5..e0f7ae2 100644
--- a/src/atomic_ops.c
+++ b/src/atomic_ops.c
@@ -101,19 +101,17 @@ AO_TS_t AO_locks[AO_HASH_SIZE] = {
AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER, AO_TS_INITIALIZER,
};
-static AO_T dummy = 1;
+static AO_t dummy = 1;
/* Spin for 2**n units. */
-void AO_spin(int n)
+static void AO_spin(int n)
{
- int i;
- AO_T j = AO_load(&dummy);
+ AO_t j = AO_load(&dummy);
+ int i = 2 << n;
- for (i = 0; i < (2 << n); ++i)
- {
- j *= 5;
- j -= 4;
- }
+ while (i-- > 0)
+ j += (j - 1) << 2;
+ /* Given 'dummy' is initialized to 1, j is 1 after the loop. */
AO_store(&dummy, j);
}