File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -8,7 +8,7 @@ project(DistributedMalloc)
88find_package (MPI REQUIRED )
99
1010# Vars with files for compilation
11- set (SRCS src/main/main.c src/utils/utils.c src/cli/cli.c src/network/message.c src/network/block.c include/block.h)
11+ set (SRCS src/main/main.c src/utils/utils.c src/cli/cli.c src/network/message.c src/network/block.c include/block.h src/utils/command_queue.c )
1212include_directories ("include/" )
1313include_directories (SYSTEM ${MPI_INCLUDE_PATH} )
1414
Original file line number Diff line number Diff line change 1+ digraph User_Command_Queue {
2+
3+ Command_1 [shape =box ]
4+ Command_2 [shape =box ]
5+ Command_3 [shape =box ]
6+ Leader [shape =diamond ]
7+
8+ Command_1 -> Command_2 -> Command_3;
9+ User -> Command_1;
10+ Command_3 -> Leader;
11+ }
Original file line number Diff line number Diff line change 1+ #ifndef DISTRIBUTEDMALLOC_COMMAND_QUEUE_H
2+ #define DISTRIBUTEDMALLOC_COMMAND_QUEUE_H
3+
4+ #include <stdlib.h>
5+
6+ enum user_command {
7+ MALLOC , // Data => Size
8+ FREE , // Data => Address
9+ WRITE , // Data => Address; Data size; Data
10+ READ , // Data => Address; Data size
11+ DUMP , // Data => Address
12+ SNAP ,
13+ DNET ,
14+ KILL , // Data => id
15+ REVIVE , // Data => id
16+ NONE
17+ };
18+
19+ struct command_queue {
20+ enum user_command command ;
21+ struct command_queue * next ;
22+ void * data ; // Contain the structure depending of the command
23+ };
24+
25+ // Delete first command queue, return head
26+ struct command_queue * pop_command (struct command_queue * head );
27+
28+ // Push command in queue, return head, can have head=NULL for init queue
29+ struct command_queue * push_command (struct command_queue * head , struct command_queue * new_elt );
30+
31+ // Get command queue data, you should known how to cast it
32+ void * peek_command (struct command_queue * head );
33+
34+ // Get user command enum of the first of the queue
35+ enum user_command peek_user_command (struct command_queue * head );
36+
37+ struct data_write {
38+ size_t address ;
39+ size_t size ;
40+ void * data ;
41+ };
42+
43+ struct data_read {
44+ size_t address ;
45+ size_t size ;
46+ };
47+
48+ struct data_id {
49+ unsigned short id ;
50+ };
51+
52+ struct data_address {
53+ size_t address ;
54+ };
55+
56+ struct data_size {
57+ size_t size ;
58+ };
59+
60+ #endif /* !DISTRIBUTEDMALLOC_COMMAND_QUEUE_H */
Original file line number Diff line number Diff line change 1+ #include "command_queue.h"
2+
3+ // Delete first command queue, return head
4+ struct command_queue * pop_command (struct command_queue * head ) {
5+ struct command_queue * new_head = NULL ;
6+ if (!head )
7+ return NULL ;
8+ else if (!head -> next ) {
9+ if (head -> data )
10+ free (head -> data );
11+ free (head );
12+ return NULL ;
13+ } else {
14+ new_head = head -> next ;
15+ if (head -> data )
16+ free (head -> data );
17+ free (head );
18+ return new_head ;
19+ }
20+ }
21+
22+ // Push command in queue, return head, can have head=NULL for init queue
23+ struct command_queue * push_command (struct command_queue * head , struct command_queue * new_elt ) {
24+ if (!head ) {
25+ return new_elt ;
26+ }
27+ struct command_queue * iter = head ;
28+ while (iter -> next ) {
29+ iter = iter -> next ;
30+ }
31+ iter -> next = new_elt ;
32+ return head ;
33+ }
34+
35+ // Get command queue data, you should known how to cast it
36+ void * peek_command (struct command_queue * head ) {
37+ if (head )
38+ return head -> data ;
39+ return NULL ;
40+ }
41+
42+ // Get user command enum of the first of the queue
43+ enum user_command peek_user_command (struct command_queue * head ) {
44+ if (head )
45+ return head -> command ;
46+ return NONE ;
47+ }
You can’t perform that action at this time.
0 commit comments