XRootD
Loading...
Searching...
No Matches
XrdEc::BufferPool Class Reference

Pool of buffer for caching writes. More...

#include <XrdEcWrtBuff.hh>

Collaboration diagram for XrdEc::BufferPool:

Public Member Functions

XrdCl::Buffer Create (const ObjCfg &objcfg)
 Create now buffer (or recycle existing one).
void Recycle (XrdCl::Buffer &&buffer)
 Give back a buffer to the poool.

Static Public Member Functions

static BufferPool & Instance ()
 Singleton access to the object.

Detailed Description

Pool of buffer for caching writes.

Definition at line 48 of file XrdEcWrtBuff.hh.

Member Function Documentation

◆ Create()

XrdCl::Buffer XrdEc::BufferPool::Create ( const ObjCfg & objcfg)
inline

Create now buffer (or recycle existing one).

Definition at line 64 of file XrdEcWrtBuff.hh.

65 {
66 std::unique_lock<std::mutex> lck( mtx );
67 //---------------------------------------------------------------------
68 // If pool is not empty, recycle existing buffer
69 //---------------------------------------------------------------------
70 if( !pool.empty() )
71 {
72 XrdCl::Buffer buffer( std::move( pool.front() ) );
73 pool.pop();
74 return buffer;
75 }
76 //---------------------------------------------------------------------
77 // Check if we can create a new buffer object without exceeding the
78 // the maximum size of the pool
79 //---------------------------------------------------------------------
80 if( currentsize < totalsize )
81 {
82 XrdCl::Buffer buffer( objcfg.blksize );
83 ++currentsize;
84 return buffer;
85 }
86 //---------------------------------------------------------------------
87 // If not, we have to wait until there is a buffer we can recycle
88 //---------------------------------------------------------------------
89 while( pool.empty() ) cv.wait( lck );
90 XrdCl::Buffer buffer( std::move( pool.front() ) );
91 pool.pop();
92 return buffer;
93 }

References XrdEc::ObjCfg::blksize.

◆ Instance()

BufferPool & XrdEc::BufferPool::Instance ( )
inlinestatic

Singleton access to the object.

Definition at line 55 of file XrdEcWrtBuff.hh.

56 {
57 static BufferPool instance;
58 return instance;
59 }

Referenced by XrdEc::WrtBuff::~WrtBuff().

Here is the caller graph for this function:

◆ Recycle()

void XrdEc::BufferPool::Recycle ( XrdCl::Buffer && buffer)
inline

Give back a buffer to the poool.

Definition at line 98 of file XrdEcWrtBuff.hh.

99 {
100 if( !buffer.GetBuffer() ) return;
101 std::unique_lock<std::mutex> lck( mtx );
102 buffer.SetCursor( 0 );
103 pool.emplace( std::move( buffer ) );
104 cv.notify_all();
105 }
const char * GetBuffer(uint32_t offset=0) const
Get the message buffer.
void SetCursor(uint32_t cursor)
Set the cursor.

Referenced by XrdEc::WrtBuff::~WrtBuff().

Here is the caller graph for this function:

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