os/ossrv/genericopenlibs/openenvcore/include/sys/sem.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/* $FreeBSD: src/sys/sys/sem.h,v 1.29 2004/11/17 13:12:06 rwatson Exp $ */
sl@0
     2
/*	$NetBSD: sem.h,v 1.5 1994/06/29 06:45:15 cgd Exp $	*/
sl@0
     3
sl@0
     4
/*
sl@0
     5
 *© * © * Portions Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
sl@0
     6
 * SVID compatible sem.h file
sl@0
     7
 *
sl@0
     8
 * Author:  Daniel Boulet
sl@0
     9
 */
sl@0
    10
sl@0
    11
#ifndef _SYS_SEM_H_
sl@0
    12
#define _SYS_SEM_H_
sl@0
    13
sl@0
    14
#include <sys/ipc.h>
sl@0
    15
sl@0
    16
sl@0
    17
struct sem {
sl@0
    18
	u_short	semval;		/* semaphore value */
sl@0
    19
	pid_t	sempid;		/* process ID of last operation */
sl@0
    20
	u_short	semncnt;	/* number of processes waiting for semval
sl@0
    21
                           to become greater than current value */
sl@0
    22
	u_short	semzcnt;	/* number of processes waiting for semval
sl@0
    23
                           to become 0 */
sl@0
    24
    };
sl@0
    25
sl@0
    26
struct semid_ds {
sl@0
    27
	struct ipc_perm	sem_perm;	/* operation permission struct */
sl@0
    28
	struct sem	*sem_base;	/* pointer to first semaphore in set */
sl@0
    29
	unsigned short	sem_nsems;	/* number of sems in set */
sl@0
    30
	time_t		sem_otime;	/* last operation time */
sl@0
    31
	long		sem_pad1;	/* SVABI/386 says I need this here */
sl@0
    32
	time_t		sem_ctime;	/* last change time */
sl@0
    33
    					/* Times measured in secs since */
sl@0
    34
    					/* 00:00:00 GMT, Jan. 1, 1970 */
sl@0
    35
	long		sem_pad2;	/* SVABI/386 says I need this here */
sl@0
    36
	long		sem_pad3[4];	/* SVABI/386 says I need this here */
sl@0
    37
};
sl@0
    38
sl@0
    39
/*
sl@0
    40
 * semop's sops parameter structure
sl@0
    41
 */
sl@0
    42
struct sembuf {
sl@0
    43
	unsigned short	sem_num;	/* semaphore # */
sl@0
    44
	short		sem_op;		/* semaphore operation */
sl@0
    45
	short		sem_flg;	/* operation flags */
sl@0
    46
};
sl@0
    47
#define SEM_UNDO	010000
sl@0
    48
sl@0
    49
/*
sl@0
    50
 * semctl's arg parameter structure
sl@0
    51
 */
sl@0
    52
union semun {
sl@0
    53
	int		val;		/* value for SETVAL */
sl@0
    54
	struct		semid_ds *buf;	/* buffer for IPC_STAT & IPC_SET */
sl@0
    55
	unsigned short	*array;		/* array for GETALL & SETALL */
sl@0
    56
};
sl@0
    57
sl@0
    58
/*
sl@0
    59
 * commands for semctl
sl@0
    60
 */
sl@0
    61
#define GETNCNT	3	/* Return the value of semncnt {READ} */
sl@0
    62
#define GETPID	4	/* Return the value of sempid {READ} */
sl@0
    63
#define GETVAL	5	/* Return the value of semval {READ} */
sl@0
    64
#define GETALL	6	/* Return semvals into arg.array {READ} */
sl@0
    65
#define GETZCNT	7	/* Return the value of semzcnt {READ} */
sl@0
    66
#define SETVAL	8	/* Set the value of semval to arg.val {ALTER} */
sl@0
    67
#define SETALL	9	/* Set semvals from arg.array {ALTER} */
sl@0
    68
#define SEM_STAT 10	/* Like IPC_STAT but treats semid as sema-index */
sl@0
    69
#define SEM_INFO 11	/* Like IPC_INFO but treats semid as sema-index */
sl@0
    70
sl@0
    71
/*
sl@0
    72
 * Permissions
sl@0
    73
 */
sl@0
    74
#define SEM_A		IPC_W	/* alter permission */
sl@0
    75
#define SEM_R		IPC_R	/* read permission */
sl@0
    76
sl@0
    77
#ifdef _KERNEL
sl@0
    78
sl@0
    79
/*
sl@0
    80
 * semaphore info struct
sl@0
    81
 */
sl@0
    82
struct seminfo {
sl@0
    83
	int	semmap,		/* # of entries in semaphore map */
sl@0
    84
		semmni,		/* # of semaphore identifiers */
sl@0
    85
		semmns,		/* # of semaphores in system */
sl@0
    86
		semmnu,		/* # of undo structures in system */
sl@0
    87
		semmsl,		/* max # of semaphores per id */
sl@0
    88
		semopm,		/* max # of operations per semop call */
sl@0
    89
		semume,		/* max # of undo entries per process */
sl@0
    90
		semusz,		/* size in bytes of undo structure */
sl@0
    91
		semvmx,		/* semaphore maximum value */
sl@0
    92
		semaem;		/* adjust on exit max value */
sl@0
    93
};
sl@0
    94
extern struct seminfo	seminfo;
sl@0
    95
sl@0
    96
/*
sl@0
    97
 * Kernel wrapper for the user-level structure
sl@0
    98
 */
sl@0
    99
struct semid_kernel {
sl@0
   100
	struct	semid_ds u;
sl@0
   101
	struct	label *label;	/* MAC framework label */
sl@0
   102
};
sl@0
   103
sl@0
   104
/* internal "mode" bits */
sl@0
   105
#define	SEM_ALLOC	01000	/* semaphore is allocated */
sl@0
   106
#define	SEM_DEST	02000	/* semaphore will be destroyed on last detach */
sl@0
   107
sl@0
   108
/*
sl@0
   109
 * Process sem_undo vectors at proc exit.
sl@0
   110
 */
sl@0
   111
void	semexit(struct proc *p);
sl@0
   112
#endif /* _KERNEL */
sl@0
   113
sl@0
   114
#ifndef _KERNEL
sl@0
   115
#include <sys/cdefs.h>
sl@0
   116
#include <sys/_types.h>
sl@0
   117
sl@0
   118
#ifndef _SIZE_T_DECLARED
sl@0
   119
typedef __size_t        size_t;
sl@0
   120
#define _SIZE_T_DECLARED
sl@0
   121
#endif
sl@0
   122
sl@0
   123
#ifndef _PID_T_DECLARED
sl@0
   124
typedef __pid_t         pid_t;
sl@0
   125
#define _PID_T_DECLARED
sl@0
   126
#endif
sl@0
   127
sl@0
   128
// FUNCTION PROTOTYPES
sl@0
   129
sl@0
   130
sl@0
   131
// FORWARD DECLARATIONS
sl@0
   132
sl@0
   133
sl@0
   134
// CLASS/STRUCT/FUNCTION DECLARATION
sl@0
   135
sl@0
   136
__BEGIN_DECLS
sl@0
   137
sl@0
   138
/*
sl@0
   139
* Get semaphore identifier using the IPC key generated by ftok.
sl@0
   140
*/
sl@0
   141
sl@0
   142
IMPORT_C int semget(key_t key, int nsems, int semflg);
sl@0
   143
sl@0
   144
sl@0
   145
/*
sl@0
   146
* Perform atomically a user-defined array of semaphore operations on the set of 
sl@0
   147
* semaphores associated with the semaphore identifier specified by the argument semid.
sl@0
   148
*/
sl@0
   149
sl@0
   150
IMPORT_C int semop(int semid, struct sembuf *sops, unsigned nsops);
sl@0
   151
sl@0
   152
sl@0
   153
/*
sl@0
   154
* Provides a variety of semaphore control operations as specified by cmd.
sl@0
   155
*/
sl@0
   156
IMPORT_C int semctl(int semid, int semnum, int cmd, ...);
sl@0
   157
sl@0
   158
sl@0
   159
__END_DECLS
sl@0
   160
#endif // #ifndef _KERNEL
sl@0
   161
sl@0
   162
#endif // _SYS_SEM_H_
sl@0
   163
sl@0
   164
//  End of File