Kaydet (Commit) afbc5792 authored tarafından Norbert Thiebaud's avatar Norbert Thiebaud Kaydeden (comit) Stephan Bergmann

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: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 581aa2ae
......@@ -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_ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment