Browse Prior Art Database

Algorithm to Support the Emulation of UNIX semop() System Call in the OS/2 Operating System

IP.com Disclosure Number: IPCOM000110872D
Original Publication Date: 1994-Jan-01
Included in the Prior Art Database: 2005-Mar-26
Document File: 4 page(s) / 112K

Publishing Venue

IBM

Related People

Hidalgo, DS: AUTHOR [+3]

Abstract

Disclosed is an invention which provides an algorithm that can be used to obtain a very close emulation of the UNIX* semop() system call in the OS/2** Operating System. The emulation of UNIX system calls is an accepted approach to porting UNIX C source code to OS/2. The differences in semaphore semantics between these two operating systems makes the emulation of UNIX semaphore system calls particularly challenging.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 38% of the total text.

Algorithm to Support the Emulation of UNIX semop() System Call in
the OS/2 Operating System

      Disclosed is an invention which provides an algorithm that can
be used to obtain a very close emulation of the UNIX* semop() system
call in the OS/2** Operating System.  The emulation of UNIX system
calls is an accepted approach to porting UNIX C source code to OS/2.
The differences in semaphore semantics between these two operating
systems makes the emulation of UNIX semaphore system calls
particularly challenging.

      An approach used to port program code written for UNIX
platforms to other operating systems such as OS/2 is to emulate the
UNIX system calls in those operating systems, along with all the
necessary semantics of those calls and the necessary header file
definitions expected by the ported source code.  Some UNIX system
calls are easier to emulate in OS/2 than others.  Of particular
interest are the emulation of the UNIX semaphore system calls.  UNIX
semaphore system calls have significantly different semantics from
those of OS/2 semaphores.  There is no direct correspondence between
any type of OS/2 semaphore and a UNIX semaphore.

      This invention provides an algorithm that can be used to obtain
a very close OS/2 emulation of the UNIX semop() system call, which is
used to manipulate an array of UNIX semaphores, also known as
semaphore sets.  The algorithm is based on a separately disclosed
data structure scheme that provides an abstracted OS/2 representation
of a single UNIX semaphore, and a set of UNIX semaphores.  The
detailed algorithm for the emulation is shown below:
int semop(int semid, struct sembuf * sops, unsigned nsops)

BEGIN

 Use the semid value to build the semaphore set's shared memory name.

  Call OS/2's DosGetNamedSharedMem() to get access to semset's
    shared memory.

  IF error connecting to the semaphore array shared memory THEN

  BEGIN

    Set errno.

    Return -1.

  END

  Lock the semset latch.

  IF error locking the semset latch, and it isn't invalid handle THEN

  BEGIN

    Set errno.

    Return -1.

  END

  ELSE IF error is invalid handle THEN

  BEGIN

    Open the semset latch semaphore.

    IF the semset latch semaphore can be opened THEN

    BEGIN

       Lock the semset latch.

      IF the semset latch can lock THEN

      BEGIN

        Open zsem and nsem event semaphores up to semnum as follows:

        BEGIN

          IF error opening an event semaphore THEN

          BEGIN

            Close all semaphores opened so far.

            Unlock the semset latch.

            Disconnect from the set's shared memory.

            Set errno.

            Return -1.

          END

        END

      END

      ELSE BEGIN

        Close the semset latch semaphore.

        Set errno.

        Return -1.

     END

 ...