sysv_sem.c (111119) | sysv_sem.c (112564) |
---|---|
1/* $FreeBSD: head/sys/kern/sysv_sem.c 111119 2003-02-19 05:47:46Z imp $ */ | 1/* $FreeBSD: head/sys/kern/sysv_sem.c 112564 2003-03-24 21:15:35Z jhb $ */ |
2 3/* 4 * Implementation of SVID semaphores 5 * 6 * Author: Daniel Boulet 7 * 8 * This software is provided ``AS IS'' without any warranties of any kind. 9 */ 10 11#include "opt_sysvipc.h" 12 13#include <sys/param.h> 14#include <sys/systm.h> 15#include <sys/sysproto.h> | 2 3/* 4 * Implementation of SVID semaphores 5 * 6 * Author: Daniel Boulet 7 * 8 * This software is provided ``AS IS'' without any warranties of any kind. 9 */ 10 11#include "opt_sysvipc.h" 12 13#include <sys/param.h> 14#include <sys/systm.h> 15#include <sys/sysproto.h> |
16#include <sys/eventhandler.h> |
|
16#include <sys/kernel.h> 17#include <sys/proc.h> 18#include <sys/lock.h> 19#include <sys/mutex.h> 20#include <sys/sem.h> 21#include <sys/syscall.h> 22#include <sys/sysent.h> 23#include <sys/sysctl.h> --- 6 unchanged lines hidden (view full) --- 30#define DPRINTF(a) printf a 31#else 32#define DPRINTF(a) 33#endif 34 35static void seminit(void); 36static int sysvsem_modload(struct module *, int, void *); 37static int semunload(void); | 17#include <sys/kernel.h> 18#include <sys/proc.h> 19#include <sys/lock.h> 20#include <sys/mutex.h> 21#include <sys/sem.h> 22#include <sys/syscall.h> 23#include <sys/sysent.h> 24#include <sys/sysctl.h> --- 6 unchanged lines hidden (view full) --- 31#define DPRINTF(a) printf a 32#else 33#define DPRINTF(a) 34#endif 35 36static void seminit(void); 37static int sysvsem_modload(struct module *, int, void *); 38static int semunload(void); |
38static void semexit_myhook(struct proc *p); | 39static void semexit_myhook(void *arg, struct proc *p); |
39static int sysctl_sema(SYSCTL_HANDLER_ARGS); 40static int semvalid(int semid, struct semid_ds *semaptr); 41 42#ifndef _SYS_SYSPROTO_H_ 43struct __semctl_args; 44int __semctl(struct thread *td, struct __semctl_args *uap); 45struct semget_args; 46int semget(struct thread *td, struct semget_args *uap); --- 14 unchanged lines hidden (view full) --- 61 62static struct mtx sem_mtx; /* semaphore global lock */ 63static int semtot = 0; 64static struct semid_ds *sema; /* semaphore id pool */ 65static struct mtx *sema_mtx; /* semaphore id pool mutexes*/ 66static struct sem *sem; /* semaphore pool */ 67SLIST_HEAD(, sem_undo) semu_list; /* list of active undo structures */ 68static int *semu; /* undo structure pool */ | 40static int sysctl_sema(SYSCTL_HANDLER_ARGS); 41static int semvalid(int semid, struct semid_ds *semaptr); 42 43#ifndef _SYS_SYSPROTO_H_ 44struct __semctl_args; 45int __semctl(struct thread *td, struct __semctl_args *uap); 46struct semget_args; 47int semget(struct thread *td, struct semget_args *uap); --- 14 unchanged lines hidden (view full) --- 62 63static struct mtx sem_mtx; /* semaphore global lock */ 64static int semtot = 0; 65static struct semid_ds *sema; /* semaphore id pool */ 66static struct mtx *sema_mtx; /* semaphore id pool mutexes*/ 67static struct sem *sem; /* semaphore pool */ 68SLIST_HEAD(, sem_undo) semu_list; /* list of active undo structures */ 69static int *semu; /* undo structure pool */ |
70static eventhandler_tag semexit_tag; |
|
69 70#define SEMUNDO_MTX sem_mtx 71#define SEMUNDO_LOCK() mtx_lock(&SEMUNDO_MTX); 72#define SEMUNDO_UNLOCK() mtx_unlock(&SEMUNDO_MTX); 73#define SEMUNDO_LOCKASSERT(how) mtx_assert(&SEMUNDO_MTX, (how)); 74 75struct sem { 76 u_short semval; /* semaphore value */ --- 121 unchanged lines hidden (view full) --- 198 } 199 for (i = 0; i < seminfo.semmni; i++) 200 mtx_init(&sema_mtx[i], "semid", NULL, MTX_DEF); 201 for (i = 0; i < seminfo.semmnu; i++) { 202 struct sem_undo *suptr = SEMU(i); 203 suptr->un_proc = NULL; 204 } 205 SLIST_INIT(&semu_list); | 71 72#define SEMUNDO_MTX sem_mtx 73#define SEMUNDO_LOCK() mtx_lock(&SEMUNDO_MTX); 74#define SEMUNDO_UNLOCK() mtx_unlock(&SEMUNDO_MTX); 75#define SEMUNDO_LOCKASSERT(how) mtx_assert(&SEMUNDO_MTX, (how)); 76 77struct sem { 78 u_short semval; /* semaphore value */ --- 121 unchanged lines hidden (view full) --- 200 } 201 for (i = 0; i < seminfo.semmni; i++) 202 mtx_init(&sema_mtx[i], "semid", NULL, MTX_DEF); 203 for (i = 0; i < seminfo.semmnu; i++) { 204 struct sem_undo *suptr = SEMU(i); 205 suptr->un_proc = NULL; 206 } 207 SLIST_INIT(&semu_list); |
206 at_exit(semexit_myhook); | |
207 mtx_init(&sem_mtx, "sem", NULL, MTX_DEF); | 208 mtx_init(&sem_mtx, "sem", NULL, MTX_DEF); |
209 semexit_tag = EVENTHANDLER_REGISTER(process_exit, semexit_myhook, NULL, 210 EVENTHANDLER_PRI_ANY); |
|
208} 209 210static int 211semunload(void) 212{ 213 int i; 214 215 if (semtot != 0) 216 return (EBUSY); 217 | 211} 212 213static int 214semunload(void) 215{ 216 int i; 217 218 if (semtot != 0) 219 return (EBUSY); 220 |
221 EVENTHANDLER_DEREGISTER(process_exit, semexit_tag); |
|
218 free(sem, M_SEM); 219 free(sema, M_SEM); 220 free(semu, M_SEM); | 222 free(sem, M_SEM); 223 free(sema, M_SEM); 224 free(semu, M_SEM); |
221 rm_at_exit(semexit_myhook); | |
222 for (i = 0; i < seminfo.semmni; i++) 223 mtx_destroy(&sema_mtx[i]); 224 mtx_destroy(&sem_mtx); 225 return (0); 226} 227 228static int 229sysvsem_modload(struct module *module, int cmd, void *arg) --- 904 unchanged lines hidden (view full) --- 1134 return (error); 1135} 1136 1137/* 1138 * Go through the undo structures for this process and apply the adjustments to 1139 * semaphores. 1140 */ 1141static void | 225 for (i = 0; i < seminfo.semmni; i++) 226 mtx_destroy(&sema_mtx[i]); 227 mtx_destroy(&sem_mtx); 228 return (0); 229} 230 231static int 232sysvsem_modload(struct module *module, int cmd, void *arg) --- 904 unchanged lines hidden (view full) --- 1137 return (error); 1138} 1139 1140/* 1141 * Go through the undo structures for this process and apply the adjustments to 1142 * semaphores. 1143 */ 1144static void |
1142semexit_myhook(p) | 1145semexit_myhook(arg, p) 1146 void *arg; |
1143 struct proc *p; 1144{ 1145 struct sem_undo *suptr; 1146 struct sem_undo **supptr; 1147 1148 /* 1149 * Go through the chain of undo vectors looking for one 1150 * associated with this process. --- 74 unchanged lines hidden --- | 1147 struct proc *p; 1148{ 1149 struct sem_undo *suptr; 1150 struct sem_undo **supptr; 1151 1152 /* 1153 * Go through the chain of undo vectors looking for one 1154 * associated with this process. --- 74 unchanged lines hidden --- |