Hi all,
I compiled the following code with gcc-3.3.1. Once without
optimization and one time with optimization -O. With optimization the
Decrement function takes a LOT longer than before whereas the
Increment function stays constant. I haven't found anything in the
manpage about it ... Any help is appreciated.
cheers,
Klaus
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
int g_Lock_Mini = 0;
inline int Increment( int* count)
{
__asm__ __volatile__( "movl $1, %%eax\n\t"
"lock; xaddl %%eax, (%%ecx)\n\t"
"incl %%eax\n\t" : : "c" (count) );
}
inline int Decrement( int * count)
{
__asm__ __volatile__( "lock; decl (%%ecx)\n\t"
"movl (%%ecx), %%eax\n\t" : : "c" (count));
}