diff options
Diffstat (limited to 'src/common/shared_memory.h')
| -rw-r--r-- | src/common/shared_memory.h | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/src/common/shared_memory.h b/src/common/shared_memory.h index 53c7fb7..43fe2f5 100644 --- a/src/common/shared_memory.h +++ b/src/common/shared_memory.h @@ -1,16 +1,39 @@ #pragma once #include <pthread.h> +#include <sstream> -#define QUEUE_SIZE 10 #define SHM_NAME "/hashtable_queue" +#define MAX_KEY_SIZE 64 +#define MAX_VALUE_SIZE 128 -enum Operations { INSERT, DELETE, GET }; +enum Operations { INSERT, DELETE, GET, PRINT }; + +struct Request { + Operations type; + char key[MAX_KEY_SIZE]; + char value[MAX_VALUE_SIZE]; +}; struct SharedMemory { - pthread_mutex_t mutex; - pthread_cond_t cond_var; - Operations queue[QUEUE_SIZE]; - int head; - int tail; + Request request; + bool processed; + char response[MAX_VALUE_SIZE]; }; + +template <typename T> +std::string serialize(const T& data) +{ + std::ostringstream oss; + oss << data; + return oss.str(); +} + +template <typename T> +T deserialize(const std::string& str) +{ + std::istringstream iss(str); + T data; + iss >> data; + return data; +} |