commit2
This commit is contained in:
parent
f2ce4a2268
commit
989dc3b6c0
|
@ -0,0 +1,6 @@
|
|||
#ifndef SEMAPHORE_H
|
||||
#define SEMAPHORE_H
|
||||
|
||||
void semOp(int semid, short sem_num, short sem_op);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef SHM_H
|
||||
#define SHM_H
|
||||
|
||||
int getShmid();
|
||||
|
||||
#endif
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue