Re: Futex Stack Test...

Liste des GroupesRevenir à cl c++ 
Sujet : Re: Futex Stack Test...
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.c++
Date : 03. May 2025, 04:02:10
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vv40u4$2kni8$1@raubtier-asyl.eternal-september.org>
References : 1 2 3 4
User-Agent : Mozilla Thunderbird
That's the atomic_stack:
header:
#pragma once
#if defined(_MSC_VER)
#include <Windows.h>
#endif
#include <atomic>
#include "dcas_atomic.h"
struct atomic_stack
{
struct link { link *next; };
atomic_stack();
atomic_stack( link *pFirstItem );
void push( link *pItem );
void push_chain( link *pFirstItem );
void push_chain( link *pFirstItem, link *pLastItem );
link *pop();
link *pop_all();
operator bool();
private:
using dcas_pair = typename dcas_atomic::pair_t;
dcas_atomic m_top;
};
inline atomic_stack::atomic_stack() :
atomic_stack( nullptr )
{
}
inline atomic_stack::atomic_stack( link *pFirstItem ) :
m_top( dcas_pair( (size_t)pFirstItem, 0 ) )
{
}
inline void atomic_stack::push_chain( link *pFirstItem )
{
link *pLastItem = pFirstItem;
for( ; pLastItem->next; pLastItem = pLastItem->next );
push_chain( pFirstItem, pLastItem );
}
inline atomic_stack::operator bool()
{
return m_top.first();
}
cpp:
#include "atomic_stack.h"
void atomic_stack::push( link *pItem )
{
dcas_pair cmp( m_top ), niu;
do
{
pItem->next = (link *)cmp.first;
niu.first = (size_t)pItem;
niu.second = cmp.second + 1;
} while( !m_top.compare_exchange( cmp, niu, dcas_release() ) );
}
void atomic_stack::push_chain( link *pFirstItem, link *pLastItem )
{
dcas_pair cmp( m_top ), niu;
do
{
pLastItem->next = (link *)cmp.first;
niu.first = (size_t)pFirstItem;
niu.second = cmp.second + 1;
} while( !m_top.compare_exchange( cmp, niu, dcas_release() ) );
}
typename atomic_stack::link *atomic_stack::pop()
{
using namespace std;
dcas_pair cmp, niu;
link *pItem;
cmp.first = m_top.first();
if( !(pItem = (link *)cmp.first) ) [[unlikely]]
return nullptr;
cmp.second = m_top.second();
for( ; ; )
{
niu.first = (size_t)pItem->next;
niu.second = cmp.second + 1;
if( m_top.compare_exchange( cmp, niu, dcas_acquire() ) ) [[likely]]
return pItem;
if( !(pItem = (link *)cmp.first) ) [[unlikely]]
return nullptr;
}
}
typename atomic_stack::link *atomic_stack::pop_all()
{
using namespace std;
dcas_pair cmp, niu;
cmp.first = m_top.first();
if( !cmp.first ) [[unlikely]]
return nullptr;
cmp.second = m_top.second();
niu.first = (size_t)nullptr;
do
niu.second = cmp.second + 1;
while( !m_top.compare_exchange( cmp, niu, dcas_acquire() ) );
return (link *)cmp.first;
}

Date Sujet#  Auteur
18 Feb 25 * Futex Stack Test...20Chris M. Thomasson
18 Feb 25 +* Re: Futex Stack Test...5Paavo Helde
18 Feb 25 i+* Re: Futex Stack Test...2James Kuyper
19 Feb 25 ii`- Re: Futex Stack Test...1Chris M. Thomasson
19 Feb 25 i+- Re: Futex Stack Test...1Chris M. Thomasson
28 Feb 25 i`- Re: Futex Stack Test...1Chris M. Thomasson
2 May 25 `* Re: Futex Stack Test...14Wuns Haerst
2 May 25  +* Re: Futex Stack Test...2Chris M. Thomasson
2 May 25  i`- Re: Futex Stack Test...1Chris M. Thomasson
3 May 25  `* Re: Futex Stack Test...11Chris M. Thomasson
3 May 25   `* Re: Futex Stack Test...10Wuns Haerst
3 May 25    `* Re: Futex Stack Test...9Bonita Montero
3 May 25     `* Re: Futex Stack Test...8Chris M. Thomasson
3 May 25      `* Re: Futex Stack Test...7Bonita Montero
3 May 25       `* Re: Futex Stack Test...6Chris M. Thomasson
4 May 25        `* Re: Futex Stack Test...5Chris M. Thomasson
8 May 25         +* Re: Futex Stack Test...2Bonita Montero
8 May 25         i`- Re: Futex Stack Test...1Chris M. Thomasson
8 May 25         `* Re: Futex Stack Test...2jseigh
10 May 25          `- Re: Futex Stack Test...1Chris M. Thomasson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal