OpenHiva::HivaBuffer

HivaBuffer is a memory type specific to the deterministic scheduling framework. You can copy data to HivaBuffer and publish HivaBuffer by invoking the Publish interface.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
namespace OpenHiva {
class HivaBuffer{
public:
    explicit HivaBuffer ();
    void ConstructFromMbuf(struct Mbuf *mbufPtr);           // Internal use for HivaBuffer construction
    uint32_t GetBuff (void *&dataPtr, size_t &dataLen);    // Obtain the start address and length of the data written to the Buff data area.
    uint32_t SetBuffDataLen(const size_t dataLen);        // Set the length of the data that is written to the Buff data area.
    uint32_t SetUserData (const UserData &data);          // Write data to the UserData area.
    uint32_t GetUserData (UserData &data);                // Obtain data from the UserData area.
    uint32_t CopyHivaBuffer(HivaBuffer &hivaBuffer);      // Copy HivaBuffer and output the new object newBuffer.
    uint32_t FreeHivaBuffer();                            // Release HivaBuffer.
private:
    Mbuf * mbufPtr_;
    friend HivaBuffPool;
    friend Publisher;
    friend BufferMessage;
};
}

Figure 1 shows the memory model.

Figure 1 HivaBuffer memory
  • The UserData class is defined as follows:
    1
    2
    3
    struct OpenHiva::UserData {
          char[96] userData;   // 96bytes
    };
    

    You can set UserData in the HivaBuffer by invoking the SetUserData interface or obtain UserData in the HivaBuffer by invoking GetUserData.

  • Pay attention to the following points when using the buffer:
    • You can invoke GetBuff to obtain the start address and length of the data to be written to Buff in HivaBuffer.
    • You can write data to Buff and then set the length of the written data by invoking SetBuffDataLen.
    • You can invoke CopyHivaBuffer to output a new HivaBuffer object newBuffer. newBuffer and the original HivaBuffer share Buff. In this case, the Buff reference count is incremented by 1. newBuffer and the original HivaBuffer have their own UserData areas, and newBuffer does not copy the UserData area of the original HivaBuffer.
    • The Buff data area can be shared among HivaBuffers. The Buff reference count is incremented by 1 each time a user is added. The life cycle of the Buff data area is different from that of HivaBuffer. When the Buff reference count is 0, the Buff data area is released.
    • The UserData area cannot be shared among HivaBuffers. Each HivaBuffer has its own UserData area. The life cycle of the UserData area is the same as that of HivaBuffer.
    • To release HivaBuffer, you can invoke the FreeHivaBuffer interface. This interface releases HivaBuffer (including the UserData area) and decreases the Buff reference count contained in HivaBuffer by 1. When the reference count is 0, the Buff data area is released.