项目文件夹

文件
Quan (Andy) Gan 4d89b54efa [Bug] Fix munmap() using wrong parameter (#2519)
* fix munmap() using wrong parameter

* rename variables

Co-authored-by: Minjie Wang <wmjlyjemaine@gmail.com>
2021-01-14 15:00:49 +08:00

85 行
2.2 KiB
C++

/*!
* Copyright (c) 2017 by Contributors
* \file dgl/runtime/ndarray.h
* \brief shared memory management.
*/
#ifndef DGL_RUNTIME_SHARED_MEM_H_
#define DGL_RUNTIME_SHARED_MEM_H_
#include <string>
namespace dgl {
namespace runtime {
/*
* \brief This class owns shared memory.
*
* When the object is gone, the shared memory will also be destroyed.
* When the shared memory is destroyed, the file corresponding to
* the shared memory is removed.
*/
class SharedMemory {
/*
* \brief whether the shared memory is owned by the object.
*
* If shared memory is created in the object, it'll be owned by the object
* and will be responsible for deleting it when the object is destroyed.
*/
bool own_;
/* \brief the file descripter of the shared memory. */
int fd_;
/* \brief the address of the shared memory. */
void *ptr_;
/* \brief the size of the shared memory. */
size_t size_;
/*
* \brief the name of the object.
*
* In Unix, shared memory is identified by a file. Thus, `name` is actually
* the file name that identifies the shared memory.
*/
std::string name;
public:
/* \brief Get the filename of shared memory file
*/
std::string GetName() const { return name; }
/*
* \brief constructor of the shared memory.
* \param name The file corresponding to the shared memory.
*/
explicit SharedMemory(const std::string &name);
/*
* \brief destructor of the shared memory.
* It deallocates the shared memory and removes the corresponding file.
*/
~SharedMemory();
/*
* \brief create shared memory.
* It creates the file and shared memory.
* \param sz the size of the shared memory.
* \return the address of the shared memory
*/
void *CreateNew(size_t sz);
/*
* \brief allocate shared memory that has been created.
* \param sz the size of the shared memory.
* \return the address of the shared memory
*/
void *Open(size_t sz);
/*
* \brief check if the shared memory exist.
* \param name the name of the shared memory.
* \return a boolean value to indicate if the shared memory exists.
*/
static bool Exist(const std::string &name);
};
} // namespace runtime
} // namespace dgl
#endif // DGL_RUNTIME_SHARED_MEM_H_