

semop()                COHERENT System Call               semop()




Perform semaphore operations

#include <sys/sem.h>
sseemmoopp(_s_e_m_i_d, _s_o_p_s, _n_s_o_p_s)
iinntt _s_e_m_i_d, _n_s_o_p_s; ssttrruucctt sseemmbbuuff(_s_o_p_s)[];

semop can atomically perform a number of operations on the set of
semaphores associated with  the semaphore identifier semid.  sops
pointer to the array of semaphore-operation structures.  nsops is
the number  of such structures in the  array.  Each structure in-
cludes the following members:


short   sem_num;    /* semaphore number */
short   sem_op;     /* semaphore operation */
short   sem_flg;    /* operation flags */


Each semaphore operation  specified by sem_op is performed on the
semaphore specified by semid and sem_num.

sem_op specifies one of three semaphore operations, as follows:

*  If sem_op is negative, one of the following occurs:

11. If  semval is greater than  or equal to the  absolute value of
   sem_op, the  absolute value of sem_op  is subtracted from sem-
   val.

22.  If semval  is  less than  the  absolute value  of sem_op  and
   (_s_e_m__f_l_g & IIPPCC_NNOOWWAAIITT) is  true, semop sets errno to EGAIN and
   returns -1.

33.  If semval  is  less than  the  absolute value  of sem_op  and
   (_s_e_m__f_l_g & IIPPCC_NNOOWWAAIITT)  is false, semop increments the semncnt
   associated with the  specified semaphore and suspend execution
   of the calling process until one of the following occurs:

aa. semval becomes greater than  or equal to the absolute value of
   _s_e_m__o_p.   When this  occurs, the  value of  semncnt associated
   with the specified  semaphore is decremented, and the absolute
   value of sem_op is subtracted from semval.

bb. The semid for which  the calling process is awaiting action is
   removed from the system.

cc. The calling process  receives a signal.  When this occurs, the
   value of  semncnt associated  with the specified  semaphore is
   decremented, and the  calling process resumes execution in the
   manner prescribed in signal.

*  If sem_op is positive, the value of sem_op is added to semval.




COHERENT Lexicon                                           Page 1




semop()                COHERENT System Call               semop()



*  If sem_op is zero, one of the following occurs:

11. If semval is zero, semop returns immediately.

22. If  semval does not  equal zero and (_s_e_m__f_l_g  & IIPPCC_NNOOWWAAIITT) is
   true, semop immediately returns -1, with eerrrrnnoo set to EGAIN.

33. If semval  is not equal to zero and  (_s_e_m__f_l_g & IIPPCC_NNOOWWAAIITT) is
   false,  semop  increments  the  semzcnt  associated  with  the
   specified  semaphore  and suspends  execution  of the  calling
   process until one of the following occurs:

aa. semval  becomes zero, at  which time the value  of semzcnt as-
   sociated with the specified semaphore is decremented.

bb. The semid for which  the calling process is awaiting action is
   removed from the system.

cc. The calling process  receives a signal.  When this occurs, the
   value of  semzcnt associated  with the specified  semaphore is
   decremented, and the  calling process resumes execution in the
   manner prescribed in signal.

semop fails if  one or more of the following  are true for any of
the semaphore operations specified by sops:

*  semid  is not a valid semaphore  identifier.  semop sets errno
   to EINVAL

*  sem_num is less than zero or greater than or equal to the num-
   ber of semaphores in the set associated with semid (EEFFBBIIGG).

*  nsops is greater than the system imposed maximum (EE22BBIIGG).

*   Operation  permission   is  denied  to  the  calling  process
   (EEAACCCCEESS).

*   The  operation  would result  in  suspension  of the  calling
   process but (_s_e_m__f_l_g & IIPPCC_NNOOWWAAIITT) is true (EEAAGGAAIINN).

*  An  operation would cause a semval to  overflow the system im-
   posed limit (EERRAANNGGEE).

*  sops points to an illegal address (EEFFAAUULLTT).

Upon  successful  completion,   the  value  of  sempid  for  each
semaphore specified in the array  pointed to by sops is set equal
to the process identifier of the calling process.

***** Return Value *****

If semop returns due to the receipt of a signal, it returns -1 to
the calling  process and sets errno to EINTR.   If it returns due
to the removal of a semid from the system, it returns -1 and sets
errno to EDOM.


COHERENT Lexicon                                           Page 2




semop()                COHERENT System Call               semop()




Upon successful completion,  semop returns the value of semval at
the time of the call for  the last operation in the array pointed
to by  sops.  Otherwise, it returns  -1 and sets errno  to an ap-
propriate value.

***** Files *****

/usr/include/sys/ipc.h
/usr/include/sys/sem.h
/dev/sem
/drv/sem

***** See Also *****

COHERENT system calls, sem, semctl(), semget()

***** Notes *****

The  flag  SEM_UNDO  is not  supported.   This  flag would  allow
semaphore  operations to  be undone upon  the termination  of the
process which performed the operations.

To improve portability,  the COHERENT system implements semaphore
operations as  a device  driver rather  than as an  actual system
call.































COHERENT Lexicon                                           Page 3


