semop [ MPE/iX Developer's Kit Reference Manual Volume II ] MPE/iX 5.0 Documentation
MPE/iX Developer's Kit Reference Manual Volume II
semop
Performs operations on a set of semaphores.
Syntax
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
int semop (int semid, struct sembuf *sops, int nsops);
Parameters
semid Passes a semaphore identifier returned by a semget() call.
sops Passes a pointer to an array of semaphore operation structures
where each element is of type struct sembuf (defined in the
<sys/sem.h> header). Semaphore operation structures define
operations to perform on the semaphore set. For details on
using semaphore operation structures, refer to the
"Description" section below.
nsops Passes the number of valid semaphore operation structures in
the array pointed to by sops.
Return Values
0 Success.
-1 An error occurred, and errno is set to indicate the error
condition.
Description
The semop() function performs operations on the set of semaphores
associated with the semaphore identifier specified by semid.
The sops argument points to an array where each of nsops elements
contains a semaphore operation structure. Each semaphore operation
specified by the sem_op field is performed on the semaphore specified by
sem_num. The operation is further defined by the sem_flg field. No
semaphore operations are performed until blocking conditions on all of
the semaphores specified in the array are removed.
If the value of sem_op is less than 0 and the calling process has write
permission, one of the following operations occurs depending upon the
current semaphore value and the value of sem_flag:
Operations when sem_op <0
-----------------------------------------------------------------------------------------------
| | | |
| Semaphore | sem_flag | Operation |
| Value | Value | |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| >= absolute value | 0 or IPC_NOWAIT | A new semaphore value is calculated as the result |
| of sem_op | | of subtracting the absolute value of sem_op from |
| | | the current semaphore value. The call to semop() |
| | | returns successfully to the calling process. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| >= absolute value | SEM_UNDO | A new semaphore value is calculated as the result |
| of sem_op | | of subtracting the absolute value of sem_op from |
| | | the current semaphore value. The absolute value of |
| | | sem_op is added to the calling process's semaphore |
| | | adjust value of the specified semaphore. The call |
| | | to semop() returns successfully to the calling |
| | | process. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| < absolute value | IPC_NOWAIT | semop() returns -1, sets errno to EAGAIN, and |
| of sem_op | | returns control to the calling process. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| < absolute value | IPC_NOWAIT not | The semncnt field is incremented, indicating the |
| of sem_op | specified | number of processes waiting for the semaphore value |
| | | of the specified semaphore to become greater than |
| | | zero. Process execution is suspended until one of |
| | | the following conditions occurs: |
| | | |
| | | * The semaphore value becomes greater than or |
| | | equal to the absolute value of sem_op. When |
| | | this occurs, the semncnt field is |
| | | decremented by 1 and execution continues as |
| | | described above when semaphore value >= |
| | | absolute value of sem_op. |
| | | * The semaphore identifier is removed from the |
| | | system. semop() returns with a value of -1 |
| | | and errno is set to EIRDM. |
| | | * A signal is caught by the suspended process. |
| | | When this occurs, the semncnt field is |
| | | decremented by 1 and the calling process |
| | | resumes execution in the manner defined by |
| | | the signal facility. |
| | | |
-----------------------------------------------------------------------------------------------
If the value of sem_op is equal to 0 and the calling process has read
permission, one of the following operations occurs depending upon the
current semaphore value and the value of sem_flag:
Operations when sem_op=0
-----------------------------------------------------------------------------------------------
| | | |
| Semaphore | sem_flag | Operation |
| Value | Value | |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| 0 | Any value | semop() executes the next semaphore operation in |
| | | the array pointed to by semops, or returns |
| | | successfully to the calling process if there are no |
| | | more valid semaphore operations. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| <>0 | IPC_NOWAIT | semop() returns -1, sets errno to EAGAIN, and |
| | | returns control to the calling process. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| <>0 | 0 or SEM_UNDO | The semzcnt field is incremented, indicating the |
| | | number of processes waiting for the semaphore value |
| | | of the specified semaphore to become zero. Process |
| | | execution is suspended until one of the following |
| | | conditions occurs: |
| | | * The semaphore value becomes zero. When this |
| | | occurs, the semzcnt field is decremented by |
| | | 1 and execution continues as described above |
| | | when semaphore value = 0. |
| | | * The specified semaphore identifier is |
| | | removed from the system. semop() returns |
| | | with a value of -1 and errno is set to |
| | | EIRDM. |
| | | * A signal is caught by the suspended process. |
| | | When this occurs, the semncnt field is |
| | | decremented by 1 and the calling process |
| | | resumes execution in the manner defined by |
| | | the signal facility. |
| | | |
-----------------------------------------------------------------------------------------------
If the value of sem_op is greater than 0 and the calling process has
write permission, one of the following operations occurs depending upon
the current semaphore value and the value of sem_flag.
Operations when sem_op>0
-----------------------------------------------------------------------------------------------
| | | |
| Semaphore | sem_flag | Operation |
| Value | Value | |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| Any value | SEM_UNDO not | A new semaphore value is calculated as the result |
| | specified | of adding the value of sem_op to the current |
| | | semaphore value of the specified semaphore. The |
| | | call to semop() returns successfully to the calling |
| | | process. |
| | | |
-----------------------------------------------------------------------------------------------
| | | |
| Any value | SEM_UNDO | A new semaphore value is calculated as the result |
| | | of adding the value of sem_op to the current |
| | | semaphore value of the specified semaphore. The |
| | | value of sem_op is subtracted from the calling |
| | | process's semaphore adjust value of the specified |
| | | semaphore. The call to semop() returns |
| | | successfully to the calling process. |
| | | |
-----------------------------------------------------------------------------------------------
If semop() is successful, the value of sempid for each semaphore
specified in the array pointed to by sops is set equal to the PID of the
calling process. The value of sem_otime in the data structure associated
with the semaphore identifier is set to the current time.
Implementation Considerations
If a process suspended during execution of semop() receives a signal,
control returns to the user with errno set to EINTR. Disabled signals are
ignored.
The maximum number of semaphore UNDO entries per process is 64.
Semaphore adjust values can be maintained for up to 64 distinct
semaphores (elements of semaphore sets).
An MPE/iX system manager can use the MPE/iX SVIPC utility to
interactively configure:
[REV BEG]
* the maximum semaphore value
* the maximum semaphore adjust value
* the maximum nsops value
* The maximum sem_op value
[REV END]
Refer to the section "Managing SVID IPC Services" for more information.
Errors
If an error occurs, errno is set to one of the following values.
E2BIG CAUSE nsops specifies a value greater than the
system-defined limit.
ACTION Check the nsops value and make sure it is within the
system-defined range.
EACCES CAUSE The calling process does not have permission.
ACTION Ensure the process has write permission (to modify a
semaphore value) or read permission (to test a
semaphore for 0).
EAGAIN CAUSE sem_flg specifies IPC_NOWAIT and the calling process
would suspend on the specified operation.
ACTION None. Application dependent.
EFAULT CAUSE The system detected a NULL or bad address in
attempting to use the sops argument.
ACTION Check to see that the sops argument has been properly
defined.
EFBIG CAUSE sem_num is either less than zero or greater than or
equal to the number of semaphores in the semaphore
set associated with semid.
ACTION Check the sem_num value to make sure it specifies a
valid semaphore in the semaphore set identified by
semid.
Table 2-0. (cont.)
EIDRM CAUSE The semaphore set specified by semid was removed
while semop() was suspended on a semaphore operation.
ACTION None.
EINTR CAUSE semget() was interrupted by a signal.
ACTION None. Application dependent.
EINVAL CAUSE semid is not a valid semaphore identifier, or the
calling process requested a SEM_UNDO for a number of
semaphores that would exceed the system-defined
limit.
ACTION Check that semid specifies a valid semaphore
identifier and that it has not been removed from the
system.
ENOSPC CAUSE The number of maximum undo entries (64) for this
process would exceed the system-defined limit.
ACTION None. There were no undo table entries available to
record the SEM_UNDO information. Examine the
application to see if SEM_UNDO is required for that
many semaphores.
ERANGE CAUSE The resulting semaphore value or semaphore adjust
value would exceed the system-defined limit.
ACTION None. Application dependent.
ESYSERR CAUSE An operating system error occurred that does not map
directly to any of the above errors.
ACTION Examine the MPE/iX process error stack for the type
of system error.
See Also
semctl(), semget(), SVID2 (Section 12)
MPE/iX 5.0 Documentation