home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / procure.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  2.8 KB  |  111 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: procure.c,v 1.8 1997/01/01 03:46:13 ldp Exp $
  4.     $Log: procure.c,v $
  5.     Revision 1.8  1997/01/01 03:46:13  ldp
  6.     Committed Amiga native (support) code
  7.  
  8.     Changed clib to proto
  9.  
  10.     Revision 1.7  1996/12/10 13:51:50  aros
  11.     Moved all #include's in the first column so makedepend can see it.
  12.  
  13.     Revision 1.6  1996/10/24 15:50:53  aros
  14.     Use the official AROS macros over the __AROS versions.
  15.  
  16.     Revision 1.5  1996/09/13 17:51:23  digulla
  17.     Use IPTR
  18.  
  19.     Revision 1.4  1996/08/13 13:56:05  digulla
  20.     Replaced AROS_LA by AROS_LHA
  21.     Replaced some AROS_LH*I by AROS_LH*
  22.     Sorted and added includes
  23.  
  24.     Revision 1.3  1996/08/01 17:41:15  digulla
  25.     Added standard header for all files
  26.  
  27.     Desc:
  28.     Lang: english
  29. */
  30. #include "exec_intern.h"
  31. #include "semaphores.h"
  32. #include <exec/semaphores.h>
  33. #include <proto/exec.h>
  34.  
  35. /*****************************************************************************
  36.  
  37.     NAME */
  38.  
  39.     AROS_LH2(ULONG, Procure,
  40.  
  41. /*  SYNOPSIS */
  42.     AROS_LHA(struct SignalSemaphore  *, sigSem, A0),
  43.     AROS_LHA(struct SemaphoreMessage *, bidMsg, A1),
  44.  
  45. /*  LOCATION */
  46.     struct ExecBase *, SysBase, 90, Exec)
  47.  
  48. /*  FUNCTION
  49.     Tries to get a lock on a semaphore in an asynchronous manner.
  50.     If the semaphore is not free this function will not wait but
  51.     just post a request to the semaphore. As soon as the semaphore is
  52.     available the bisMsg will return and make you owner of the semaphore.
  53.  
  54.     INPUTS
  55.     sigSem - pointer to semaphore structure
  56.     bidMsg - pointer to a struct SemaphoreMessage. This should lie in
  57.          public or at least shared memory.
  58.  
  59.     RESULT
  60.     Principly none. Don't know. Just ignore it.
  61.  
  62.     NOTES
  63.     Locks obtained with Procure() must be released with Vacate().
  64.  
  65.     EXAMPLE
  66.  
  67.     BUGS
  68.  
  69.     SEE ALSO
  70.     Vacate()
  71.  
  72.     INTERNALS
  73.  
  74.     HISTORY
  75.     29-10-95    digulla automatically created from
  76.                 exec_lib.fd and clib/exec_protos.h
  77.     22-01-96    fleischer implementation
  78.  
  79. *****************************************************************************/
  80. {
  81.     AROS_LIBFUNC_INIT
  82.     AROS_LIBBASE_EXT_DECL(struct ExecBase *,SysBase)
  83.  
  84.     /* Prepare semaphore message to be a sent message */
  85.     bidMsg->ssm_Message.mn_Length=sizeof(struct SemaphoreMessage);
  86.     bidMsg->ssm_Message.mn_Node.ln_Type=NT_MESSAGE;
  87.  
  88.     /* Arbitrate for the semaphore structure */
  89.     Forbid();
  90.  
  91.     /* Try to get the semaphore immediately. */
  92.     if((IPTR)(bidMsg->ssm_Message.mn_Node.ln_Name)==SM_SHARED?
  93.        AttemptSemaphoreShared(sigSem):AttemptSemaphore(sigSem))
  94.     {
  95.     /* Got it. Reply the message. */
  96.     bidMsg->ssm_Semaphore=sigSem;
  97.     ReplyMsg(&bidMsg->ssm_Message);
  98.     }
  99.     else
  100.     /* Couldn't get it. Add message to the semaphore's waiting queue. */
  101.     AddTail((struct List *)&sigSem->ss_WaitQueue,&bidMsg->ssm_Message.mn_Node);
  102.  
  103.     /* All done. */
  104.     Permit();
  105.  
  106.     /* Huh? */
  107.     return 0;
  108.     AROS_LIBFUNC_EXIT
  109. } /* Procure */
  110.  
  111.