This commit is contained in:
Edi De Candido 2023-05-14 18:51:32 +02:00
parent f2ce4a2268
commit 989dc3b6c0
5 changed files with 62 additions and 0 deletions

6
inc/custom_sem.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef SEMAPHORE_H
#define SEMAPHORE_H
void semOp(int semid, short sem_num, short sem_op);
#endif

6
inc/custom_shm.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef SHM_H
#define SHM_H
int getShmid();
#endif

35
inc/structures.h Normal file
View File

@ -0,0 +1,35 @@
#ifndef STRUCTURES_H
#define STRUCTURES_H
#define KEYFILE "../LICENSE"
// semaphore
union semun {
int val;
struct semid_ds * buf;
unsigned short * array;
};
// shared memory
typedef struct {
int collums;
int rows;
char player1Token;
char player2Token;
} input_server_t;
typedef enum {
EMPTY,
PLAYER1,
PLAYER2
} tile_t;
typedef struct {
tile_t *board;
input_server_t inS;
} shm_t;
static const size_t SHM_SIZE = sizeof(shm_t);
#endif

BIN
main Executable file

Binary file not shown.

15
src/custom_shm.c Normal file
View File

@ -0,0 +1,15 @@
#include <sys/shm.h>
#include <sys/stat.h>
#include <custom_shm.h>
#include <structures.h>
#include <errExit.h>
int getShmid() {
int result = shmget(ftok(KEYFILE, 'a'), SHM_SIZE, IPC_CREAT | S_IRUSR | S_IWUSR);
if (result == -1) {
errExit("shmget", "getShmid");
}
return result;
}