diff options
| author | Christian Krinitsin <mail@krinitsin.com> | 2025-03-21 15:11:06 +0100 |
|---|---|---|
| committer | Christian Krinitsin <mail@krinitsin.com> | 2025-03-21 15:11:06 +0100 |
| commit | fb3fdf2262a7ced18009516f00473aa975aaa08a (patch) | |
| tree | 80ed1ad5ac9cf56107286d8ee6782ae9f18f7692 /src/common/shared_memory.h | |
| parent | 44f772a7442e617d4a93c0b3ed318ffb42991d8b (diff) | |
| download | BT-Programming-Assignment-fb3fdf2262a7ced18009516f00473aa975aaa08a.tar.gz BT-Programming-Assignment-fb3fdf2262a7ced18009516f00473aa975aaa08a.zip | |
implement a queue with a mutex to prevent concurrent accesses to the shared memory
Diffstat (limited to '')
| -rw-r--r-- | src/common/shared_memory.h | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/common/shared_memory.h b/src/common/shared_memory.h index 43fe2f5..70554e4 100644 --- a/src/common/shared_memory.h +++ b/src/common/shared_memory.h @@ -4,6 +4,8 @@ #include <sstream> #define SHM_NAME "/hashtable_queue" +#define QUEUE_SIZE 10 + #define MAX_KEY_SIZE 64 #define MAX_VALUE_SIZE 128 @@ -13,12 +15,17 @@ struct Request { Operations type; char key[MAX_KEY_SIZE]; char value[MAX_VALUE_SIZE]; + char response[MAX_VALUE_SIZE]; }; struct SharedMemory { - Request request; - bool processed; - char response[MAX_VALUE_SIZE]; + Request request[QUEUE_SIZE]; + pthread_mutex_t mutex; + pthread_cond_t cond_var; + + int tail; + int head; + bool full; }; template <typename T> |