Created
May 20, 2019 19:27
-
-
Save QiMata/e7192eb93a0910787e0244241351e5e9 to your computer and use it in GitHub Desktop.
This gist is to showcase boost interprocess. Creating a set of classes to create an interface for me to create a shared memory layer for high level languages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/interprocess/shared_memory_object.hpp> | |
struct shm_remove | |
{ | |
public: | |
explicit shm_remove(const std::string& shm_name) | |
: shm_name_(shm_name) | |
{ | |
// boost::interprocess::shared_memory_object::remove(shm_name.c_str()); | |
} | |
~shm_remove(){ boost::interprocess::shared_memory_object::remove(shm_name_.c_str()); } | |
private: | |
std::string shm_name_; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <size_t MESSAGE_SIZE> | |
struct InterprocessMessage | |
{ | |
//Items to fill | |
char message[MESSAGE_SIZE]; | |
//Message size | |
size_t message_length; | |
std::string to_string() const | |
{ | |
return std::string(message,message_length); | |
} | |
}; | |
template <size_t MESSAGE_SIZE> | |
struct TraceQueue | |
{ | |
TraceQueue() | |
: message_in(false) | |
{} | |
//Mutex to protect access to the queue | |
boost::interprocess::interprocess_mutex mutex; | |
//Condition to wait when the queue is empty | |
boost::interprocess::interprocess_condition cond_empty; | |
//Condition to wait when the queue is full | |
boost::interprocess::interprocess_condition cond_full; | |
//Message | |
InterprocessMessage<MESSAGE_SIZE> message; | |
//Is there any message | |
bool message_in; | |
//Notify closing shop | |
bool closing_stream = false; | |
//Check to see if memory has been created | |
int name_length; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment