AW: [fpc-devel] Lock Free Memory Management
Peter Vreman
peter at freepascal.org
Sat Aug 19 20:29:18 CEST 2006
At 19:45 19-8-2006, you wrote:
>Helmut Hartl wrote:
> > > >> Does the Codegenerator already support this?
> > > >> Are they portable?
> > > >> How would you suggest to implement such operations platform
> > > independent?
> > > >
> > > > I don't think this is possible, as it depends on processor support
> > ?
> > >
> > > I think it can be implemented easily using
> > InterlockedCompareExchange,
> > > no?
> >
> > Yes it will be but to my knowledge there exists no platform independent
> > version of InterlockedCompareExchange in Free Pascal...and even none for
> > 64Bit.
>
>That's true.
>
> >
> > For a new memory manager there must be a lowlevel function supporting
> > this.
> > Also this operation must not be reordered/optimized by the compiler.
> >
> > The operation should preferrably be a
> > InterlockedCompareExchangePointer()
> > wich always does the right thing :-) depending on architecture ...
Maybe you should first in the RTL code before writing something, from
systemh.inc:
function InterLockedIncrement (var Target: longint) : longint; public
name 'FPC_INTERLOCKEDINCREMENT';
function InterLockedDecrement (var Target: longint) : longint; public
name 'FPC_INTERLOCKEDDECREMENT';
function InterLockedExchange (var Target: longint;Source : longint) :
longint; public name 'FPC_INTERLOCKEDEXCHANGE';
function InterLockedExchangeAdd (var Target: longint;Source :
longint) : longint; public name 'FPC_INTERLOCKEDEXCHANGEADD';
function InterlockedCompareExchange(var Target: longint; NewValue:
longint; Comperand: longint): longint; public name
'FPC_INTERLOCKEDCOMPAREEXCHANGE';
{$ifdef cpu64}
function InterLockedIncrement64 (var Target: int64) : int64; public
name 'FPC_INTERLOCKEDINCREMENT64';
function InterLockedDecrement64 (var Target: int64) : int64; public
name 'FPC_INTERLOCKEDDECREMENT64';
function InterLockedExchange64 (var Target: int64;Source : int64) :
int64; public name 'FPC_INTERLOCKEDEXCHANGE64';
function InterLockedExchangeAdd64 (var Target: int64;Source : int64)
: int64; public name 'FPC_INTERLOCKEDEXCHANGEADD64';
function InterlockedCompareExchange64(var Target: int64; NewValue:
int64; Comperand: int64): int64; public name
'FPC_INTERLOCKEDCOMPAREEXCHANGE64';
{$endif cpu64}
{ Pointer overloads }
{$ifdef cpu64}
function InterLockedIncrement (var Target: Pointer) : Pointer;
external name 'FPC_INTERLOCKEDINCREMENT64';
function InterLockedDecrement (var Target: Pointer) : Pointer;
external name 'FPC_INTERLOCKEDDECREMENT64';
function InterLockedExchange (var Target: Pointer;Source : Pointer) :
Pointer; external name 'FPC_INTERLOCKEDEXCHANGE64';
function InterLockedExchangeAdd (var Target: Pointer;Source :
Pointer) : Pointer; external name 'FPC_INTERLOCKEDEXCHANGEADD64';
function InterlockedCompareExchange(var Target: Pointer; NewValue:
Pointer; Comperand: Pointer): Pointer; external name
'FPC_INTERLOCKEDCOMPAREEXCHANGE64';
{$else cpu64}
function InterLockedIncrement (var Target: Pointer) : Pointer;
external name 'FPC_INTERLOCKEDINCREMENT';
function InterLockedDecrement (var Target: Pointer) : Pointer;
external name 'FPC_INTERLOCKEDDECREMENT';
function InterLockedExchange (var Target: Pointer;Source : Pointer) :
Pointer; external name 'FPC_INTERLOCKEDEXCHANGE';
function InterLockedExchangeAdd (var Target: Pointer;Source :
Pointer) : Pointer; external name 'FPC_INTERLOCKEDEXCHANGEADD';
function InterlockedCompareExchange(var Target: Pointer; NewValue:
Pointer; Comperand: Pointer): Pointer; external name
'FPC_INTERLOCKEDCOMPAREEXCHANGE';
{$endif cpu64}
Peter
More information about the fpc-devel
mailing list