diff options
author | Norbert Thiebaud <nthiebaud@gmail.com> | 2012-09-16 01:59:07 -0500 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2012-09-17 14:34:36 +0200 |
commit | afbc57927854c423e12206c048bbe7c285a4d9a6 (patch) | |
tree | 573922dd4b17a414e4ef0ebba4a53d257a153118 /sal | |
parent | Improvement on previous commit (diff) | |
download | core-afbc57927854c423e12206c048bbe7c285a4d9a6.tar.gz core-afbc57927854c423e12206c048bbe7c285a4d9a6.zip |
add osl_atomic_* api to allow for inlined atomic increment/decrement
atomic increment/decrement is provided by
osl_increment/decrementInterlockedCount()
but that is a exported dll function, so it cannot be inlined.
valgrind analysis of a run, loading a medium sized spreadsheet, shows
that these 2 functions were called 3.5 millions times for a total cost of
55 millions of instructions... a cost of 8 instructions per call,
which is at least a 300% overhead since an atomic inc/dec is 2 instructions
iow we could save about 1% of the total instruction count of that run(4.6B)
We cannot change the existing api, as this would break ABI.
but we can add a new api. and migrate internal user to it.
osl_atomic_decrement/osl_atomic_increment do the same task,
than osl_*IntelockedCount() but do that inlined if possible.
Note that this version only optimize the case GCC with atomic built-in.
but support for other case should not be very hard.
follows-up patches will replace the use of the osl_*InterlockedCount()
in the product with their osl_atomic_* equivalent.
Change-Id: If4dcbf94ea6f62eb6d55d30613fe65878ffb8023
Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/inc/osl/interlck.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/sal/inc/osl/interlck.h b/sal/inc/osl/interlck.h index 858f99f854d5..f8cd56e6e72b 100644 --- a/sal/inc/osl/interlck.h +++ b/sal/inc/osl/interlck.h @@ -52,10 +52,48 @@ SAL_DLLPUBLIC oslInterlockedCount SAL_CALL osl_incrementInterlockedCount(oslInte */ SAL_DLLPUBLIC oslInterlockedCount SAL_CALL osl_decrementInterlockedCount(oslInterlockedCount* pCount); + +/** Increments the count variable addressed by pCount. + @param pCount Address of counter variable + @return The result of the operation is zero, the value of the count variable. +*/ + +/// @cond INTERNAL + +/** Increments the count variable addressed by p. + @param p Address of counter variable + @attention This functionality should only be used internally within + LibreOffice. + + @return The adjusted value of the count variable. +*/ +#if defined( HAVE_GCC_BUILTIN_ATOMIC ) +# define osl_atomic_increment(p) __sync_add_and_fetch((p), 1) +#else +# define osl_atomic_increment(p) osl_incrementInterlockedCount(p) +#endif + + +/** Decrement the count variable addressed by p. + @param p Address of counter variable + @attention This functionality should only be used internally within + LibreOffice. + + @return The adjusted value of the count variable. +*/ +#if defined( HAVE_GCC_BUILTIN_ATOMIC ) +# define osl_atomic_decrement(p) __sync_sub_and_fetch((p), 1) +#else +# define osl_atomic_decrement(p) osl_decrementInterlockedCount(p) +#endif + +/// @endcond + #ifdef __cplusplus } #endif + #endif /* _OSL_INTERLOCK_H_ */ |