BPX1SOP (semop) example

The following code retrieves the PID of the last process to update semaphore 4 from the SEM_ID semaphore set. For the callable service, see semop (BPX1SOP, BPX4SOP) — Perform semaphore serialization operations. For the data structure, see BPXYSEM — Map interprocess communication semaphores. AMODE 64 callers use BPX4SOP (semop) example.
                                              
         LA    R5,BUFFERA            ->Utitliy buffer                   
         ST    R5,BUFA                                                  
         USING SEM_BUF_ELE,R5        ->1st SEM_BUF_ELE                  
         MVC   SEM_NUM(2),=AL2(0)    Semaphore number 0                 
         MVC   SEM_OP(2),=AL2(-1)              take the resource        
         MVC   SEM_FLG(2),=AL2(SEM_UNDO)       flags (undo,wait)        
         LA    R5,SEM#BUFLEN(,R5)    ->next SEM_BUF_ELE                 
         MVC   SEM_NUM(2),=AL2(2)              number 2                 
         MVC   SEM_OP(2),=AL2(1)               release the resource     
         MVC   SEM_FLG(2),=AL2(IPC_NOWAIT)     flags (nowait)           
         LA    R5,SEM#BUFLEN(,R5)              ->next SEM_BUF_ELE       
         MVC   SEM_NUM(2),=AL2(8)              number 8                 
         MVC   SEM_OP(2),=AL2(0)               test for no resource     
         MVC   SEM_FLG(2),=AL2(0)              flags (wait)             
         SPACE ,                                                        
         MVC   NUMB_SEM_OPS(4),=AL2(3) number of SEM_BUF_ELE in BUFFERA 
         SPACE ,                                                        
         CALL  BPX1SOP,              Semaphore control operations      +
               (SEM_ID,              Input: Semaphore set ID           +
               BUFA,                 Input: ->SEM_BUF_ELE      BPXYSEM +
               NUMB_SEM_OPS,         Input: Action to take             +
               RETVAL,               Return value: 0, -1 or value      +
               RETCODE,              Return code                       +
               RSNCODE),             Reason code                       +
               VL,MF=(E,PLIST)       ----------------------------------