Painless
A framework to ease parallelization of sequential CDCL SAT solvers
Loading...
Searching...
No Matches
SharingEntity Class Referenceabstract

A base class representing entities that can exchange clauses between themselves. More...

#include <SharingEntity.hpp>

Inheritance diagram for SharingEntity:
Collaboration diagram for SharingEntity:

Public Member Functions

 SharingEntity ()
 Construct a new SharingEntity object.
 
 SharingEntity (const std::vector< std::shared_ptr< SharingEntity > > &clients)
 Construct a new SharingEntity object.
 
virtual ~SharingEntity ()
 Destroy the SharingEntity object.
 
virtual bool importClause (const ClauseExchangePtr &clause)=0
 Import a single clause to this sharing entity.
 
virtual void importClauses (const std::vector< ClauseExchangePtr > &v_clauses)=0
 Import multiple clauses to this sharing entity.
 
int getSharingId () const
 Get the sharing ID of this entity.
 
void setSharingId (int _id)
 Set the sharing ID of this entity.
 
virtual void addClient (std::shared_ptr< SharingEntity > client)
 Add a client to this entity.
 
virtual void removeClient (std::shared_ptr< SharingEntity > client)
 Remove a specific client from this entity.
 
size_t getClientCount () const
 Get the current number of clients.
 
void clearClients ()
 Remove all clients.
 

Protected Member Functions

virtual bool exportClauseToClient (const ClauseExchangePtr &clause, std::shared_ptr< SharingEntity > client)
 Export a clause to a specific client.
 
bool exportClause (const ClauseExchangePtr &clause)
 Export a clause to all registered clients.
 
void exportClauses (const std::vector< ClauseExchangePtr > &clauses)
 Export multiple clauses to all registered clients.
 

Protected Attributes

std::vector< std::weak_ptr< SharingEntity > > m_clients
 List of weak pointers to client SharingEntities.
 
std::shared_mutex m_clientsMutex
 Mutex to protect access to m_clients.
 

Detailed Description

A base class representing entities that can exchange clauses between themselves.

Warning
This class assumes all SharingEntity objects are managed by std::shared_ptr. Improper use of raw pointers or other smart pointer types may lead to undefined behavior.
Todo

Test userspace RCU for m_clients list

shared_from_this is needed here ? Or only when we deal with producers in a SharingStrategy ?

Constructor & Destructor Documentation

◆ SharingEntity() [1/2]

SharingEntity::SharingEntity ( )
inline

Construct a new SharingEntity object.

Automatically assigns a unique sharing ID to the entity.

Warning
This constructor should only be called through std::make_shared or a similar mechanism that ensures the object is owned by a shared_ptr.

◆ SharingEntity() [2/2]

SharingEntity::SharingEntity ( const std::vector< std::shared_ptr< SharingEntity > > & clients)
inline

Construct a new SharingEntity object.

Automatically assigns a unique sharing ID to the entity.

Warning
This constructor should only be called through std::make_shared or a similar mechanism that ensures the object is owned by a shared_ptr.

Member Function Documentation

◆ addClient()

virtual void SharingEntity::addClient ( std::shared_ptr< SharingEntity > client)
inlinevirtual

Add a client to this entity.

Parameters
clientshared pointer to the client SharingEntity to add.

◆ exportClause()

bool SharingEntity::exportClause ( const ClauseExchangePtr & clause)
inlineprotected

Export a clause to all registered clients.

Parameters
clauseThe clause to export.
Returns
true if the clause was exported to any client, false otherwise.
Note
This method uses the exportClauseToClient primitive for each clause and client combination. Subclasses can customize the behavior of clause export by overriding the exportClauseToClient method.

◆ exportClauses()

void SharingEntity::exportClauses ( const std::vector< ClauseExchangePtr > & clauses)
inlineprotected

Export multiple clauses to all registered clients.

Parameters
clausesA vector of clauses to export.
Note
This method uses the exportClauseToClient primitive for each clause and client combination. Subclasses can customize the behavior of clause export by overriding the exportClauseToClient method.

◆ exportClauseToClient()

virtual bool SharingEntity::exportClauseToClient ( const ClauseExchangePtr & clause,
std::shared_ptr< SharingEntity > client )
inlineprotectedvirtual

Export a clause to a specific client.

Parameters
clauseThe clause to export.
clientThe client to export the clause to.
Returns
true if the clause was exported to the client, false otherwise.
Note
This is a primitive method intended to be redefined by subclasses. It is used by the exportClauses method to handle the export of individual clauses.
Warning
This method is not thread-safe and cannot be called concurrently.

Reimplemented in GlobalSharingStrategy, MallobSharing, and SharingStrategy.

◆ getClientCount()

size_t SharingEntity::getClientCount ( ) const
inline

Get the current number of clients.

Returns
The number of clients currently registered with this entity.

This method is thread-safe and can be called concurrently. Note: This count includes expired weak pointers that haven't been cleaned up yet.

◆ getSharingId()

int SharingEntity::getSharingId ( ) const
inline

Get the sharing ID of this entity.

Returns
The sharing ID.

◆ importClause()

virtual bool SharingEntity::importClause ( const ClauseExchangePtr & clause)
pure virtual

Import a single clause to this sharing entity.

Parameters
clauseThe clause to add.
Returns
true if clause was imported, false otherwise.
Warning
This method may be called concurrently from multiple threads. Derived classes should ensure thread-safety in their implementation.

Implemented in Cadical, GlobalSharingStrategy, GlucoseSyrup, HordeSatSharing, Kissat, KissatINCSolver, KissatMABSolver, Lingeling, MallobSharing, MapleCOMSPSSolver, MiniSat, and SimpleSharing.

◆ importClauses()

virtual void SharingEntity::importClauses ( const std::vector< ClauseExchangePtr > & v_clauses)
pure virtual

Import multiple clauses to this sharing entity.

Parameters
v_clausesThe vector with the clauses to add.
Warning
This method may be called concurrently from multiple threads. Derived classes should ensure thread-safety in their implementation.

Implemented in Cadical, GlobalSharingStrategy, GlucoseSyrup, HordeSatSharing, Kissat, KissatINCSolver, KissatMABSolver, Lingeling, MapleCOMSPSSolver, MiniSat, and SimpleSharing.

◆ removeClient()

virtual void SharingEntity::removeClient ( std::shared_ptr< SharingEntity > client)
inlinevirtual

Remove a specific client from this entity.

Parameters
clientshared pointer to the client SharingEntity to remove.

This method is thread-safe and can be called concurrently.

◆ setSharingId()

void SharingEntity::setSharingId ( int _id)
inline

Set the sharing ID of this entity.

Parameters
_idThe new sharing ID.

The documentation for this class was generated from the following file: