/* shm.h
* PSR 3shm assignment
* DO NOT MODIFY
*/
#ifndef PSR3SHM_H
#define PSR3SHM_H
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <semLib.h>
#include <fcntl.h>
struct company {
char name[20];
int work_done;
};
struct company_registry {
struct company companies[50];
};
/* ndef trick to avoid "multiple definition errors".
Just use '#define SHM_C' inside the 'shm.c' file before including
this header file.
*/
#ifdef SHM_C
#define EXTERN
#else
#define EXTERN extern
#endif
/* Pointer to the shared registry. */
EXTERN struct company_registry *ptr;
/* Lock for protecting shared registry. */
EXTERN SEM_ID lock;
/*
* init_shm()
* : (char*) company_name -- Name of the company to be registered.
*
* This function should "create access" to the shared memory.
* In addition, when executed from a company, it should register
* this company into the registry and return a pointer to the taken
* company struct.
*
* See assignment page for a sample code.
*/
struct company* init_shm(char* company_name);
#endif