Skip to content

Commit

Permalink
Secure pipeline ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
d-frey committed Jan 2, 2025
1 parent 7374901 commit 3e6cf59
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion include/tao/pq/pipeline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,25 @@
namespace tao::pq
{
class connection;
class transaction;

class pipeline
: public transaction_base
{
private:
std::shared_ptr< transaction_base > m_previous;

friend class transaction;

// pass-key idiom
class private_key final
{
private_key() = default;
friend class transaction;
};

public:
explicit pipeline( const std::shared_ptr< pq::connection >& connection );
pipeline( const private_key /*unused*/, const std::shared_ptr< pq::connection >& connection );

~pipeline() override
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pq/pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace tao::pq
{
pipeline::pipeline( const std::shared_ptr< pq::connection >& connection )
pipeline::pipeline( const pipeline::private_key /*unused*/, const std::shared_ptr< pq::connection >& connection )
: transaction_base( connection ),
m_previous( current_transaction()->shared_from_this() )
{
Expand Down
2 changes: 1 addition & 1 deletion src/lib/pq/transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ namespace tao::pq
auto transaction::pipeline() -> std::shared_ptr< pq::pipeline >
{
check_current_transaction();
return std::make_shared< pq::pipeline >( m_connection );
return std::make_shared< pq::pipeline >( pq::pipeline::private_key(), m_connection );
}

void transaction::commit()
Expand Down

0 comments on commit 3e6cf59

Please sign in to comment.