home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 5 / Amiga Tools 5.iso / tools / developer-tools / aros / source / exec / semaphores / src / procure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-16  |  2.1 KB  |  88 lines

  1. /*
  2.     $Id$
  3.     $Log$
  4.     Desc:
  5.     Lang: english
  6. */
  7. #include "exec_intern.h"
  8. #include "semaphores.h"
  9.  
  10. /*****************************************************************************
  11.  
  12.     NAME */
  13.     #include <exec/semaphores.h>
  14.     #include <clib/exec_protos.h>
  15.  
  16.     __AROS_LH2(ULONG, Procure,
  17.  
  18. /*  SYNOPSIS */
  19.     __AROS_LA(struct SignalSemaphore  *, sigSem, A0),
  20.     __AROS_LA(struct SemaphoreMessage *, bidMsg, A1),
  21.  
  22. /*  LOCATION */
  23.     struct ExecBase *, SysBase, 90, Exec)
  24.  
  25. /*  FUNCTION
  26.     Tries to get a lock on a semaphore in an asynchronous manner.
  27.     If the semaphore is not free this function will not wait but
  28.     just post a request to the semaphore. As soon as the semaphore is
  29.     available the bisMsg will return and make you owner of the semaphore.
  30.  
  31.     INPUTS
  32.     sigSem - pointer to semaphore structure
  33.     bidMsg - pointer to a struct SemaphoreMessage. This should lie in
  34.          public or at least shared memory.
  35.  
  36.     RESULT
  37.     Principly none. Don't know. Just ignore it.
  38.  
  39.     NOTES
  40.     Locks obtained with Procure() must be released with Vacate().
  41.  
  42.     EXAMPLE
  43.  
  44.     BUGS
  45.  
  46.     SEE ALSO
  47.     Vacate()
  48.  
  49.     INTERNALS
  50.  
  51.     HISTORY
  52.     29-10-95    digulla automatically created from
  53.                 exec_lib.fd and clib/exec_protos.h
  54.     22-01-96    fleischer implementation
  55.  
  56. *****************************************************************************/
  57. {
  58.     __AROS_FUNC_INIT
  59.     __AROS_BASE_EXT_DECL(struct ExecBase *,SysBase)
  60.  
  61.     /* Prepare semaphore message to be a sent message */
  62.     bidMsg->ssm_Message.mn_Length=sizeof(struct SemaphoreMessage);
  63.     bidMsg->ssm_Message.mn_Node.ln_Type=NT_MESSAGE;
  64.  
  65.     /* Arbitrate for the semaphore structure */
  66.     Forbid();
  67.  
  68.     /* Try to get the semaphore immediately. */
  69.     if((ULONG)bidMsg->ssm_Message.mn_Node.ln_Name==SM_SHARED?
  70.        AttemptSemaphoreShared(sigSem):AttemptSemaphore(sigSem))
  71.     {
  72.     /* Got it. Reply the message. */
  73.     bidMsg->ssm_Semaphore=sigSem;
  74.     ReplyMsg(&bidMsg->ssm_Message);
  75.     }
  76.     else
  77.     /* Couldn't get it. Add message to the semaphore's waiting queue. */
  78.     AddTail((struct List *)&sigSem->ss_WaitQueue,&bidMsg->ssm_Message.mn_Node);
  79.  
  80.     /* All done. */
  81.     Permit();
  82.  
  83.     /* Huh? */
  84.     return 0;
  85.     __AROS_FUNC_EXIT
  86. } /* Procure */
  87.  
  88.