Skip to content

Instantly share code, notes, and snippets.

@davidsan
Created February 26, 2013 20:59
Show Gist options
  • Select an option

  • Save davidsan/5042137 to your computer and use it in GitHub Desktop.

Select an option

Save davidsan/5042137 to your computer and use it in GitHub Desktop.
patch libIPC @osx 10.8.2
$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.8.2
BuildVersion: 12C60
# Nom du repertoire ou generer la libIPC
REP = ../lib
# Nom du fichier a generer :
# <---
LIBRAIRIE = $(REP)/libIPC.a
# Fichiers C necessaires a la compilation :
# <---
CFILES = shmem.c sem.c
# <-
INCDIR = -iquote
# Fichiers objets :
# <
CFLAGS = $(GFLAGS) $(INCDIR) -Wall
OFILES = $(CFILES:.c=.o)
CC = gcc
$(LIBRAIRIE) : $(OFILES)
@echo "Building $@ ... "
ar r $@ $(OFILES); ranlib $@
@echo "$@ done"
clean:; rm -f $(OFILES) $(LIBRAIRIE) core
sem.o: sem.c
$(CC) -c sem.c $(CFLAGS)
shmem.o: shmem.c
$(CC) -c shmem.c $(CFLAGS)
/*
* sem.c
*
* 2001 Pierre Sens (Pierre.Sens@lip6.fr)
*
* Fonction de manipulation de semaphores
*
*/
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
//#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
// /* union semun is defined by including <sys/sem.h> */
//#else
// /* according to X/OPEN we have to define it ourselves */
//union semun {
// int val; /* value for SETVAL */
// struct semid_ds *buf; /* buffer for IPC_STAT, IPC_SET */
// unsigned short int *array; /* array for GETALL, SETALL */
// struct seminfo *__buf; /* buffer for IPC_INFO */
//#endif
int semid;
struct sembuf operation;
union semun arg;
int creer_sem(int nbsem)
{
int flags = 0666 | IPC_CREAT;
return (semid=semget(IPC_PRIVATE, nbsem, flags));
}
int init_sem(ushort *argvect)
{
arg.array = argvect;
return semctl(semid, 1, SETALL, arg);
}
int init_un_sem(int semnum, ushort argsem)
{
arg.val = argsem;
return semctl(semid, semnum, SETVAL, arg);
}
int det_sem()
{
return semctl(semid, 1, IPC_RMID, arg);
}
void P(int sem)
{
operation.sem_num=sem;
operation.sem_op = -1;
/* operation.sem_flg=SEM_UNDO;*/
if (semop(semid,&operation,1)) {
perror("Erreur dans P");
exit(1);
}
}
void V(int sem)
{
operation.sem_num=sem;
operation.sem_op = 1;
/* operation.sem_flg=SEM_UNDO;*/
if (semop(semid,&operation,1)) {
perror("Erreur dans V");
exit(1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment