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

  1. /*
  2.     $Id$
  3.     $Log$
  4.     Desc:
  5.     Lang: english
  6. */
  7. #include "exec_intern.h"
  8.  
  9. /*****************************************************************************
  10.  
  11.     NAME */
  12.     #include <exec/semaphores.h>
  13.     #include <clib/exec_protos.h>
  14.  
  15.     __AROS_LH1(ULONG, AttemptSemaphore,
  16.  
  17. /*  SYNOPSIS */
  18.     __AROS_LA(struct SignalSemaphore *, sigSem, A0),
  19.  
  20. /*  LOCATION */
  21.     struct ExecBase *, SysBase, 96, Exec)
  22.  
  23. /*  FUNCTION
  24.     Tries to get an exclusive lock on a signal semaphore. If the semaphore
  25.     is already in use by another task this function does not wait but
  26.     return false instead.
  27.  
  28.     INPUTS
  29.     sigSem - Pointer so semaphore structure.
  30.  
  31.     RESULT
  32.     TRUE if the semaphore could be obtained, FALSE otherwise.
  33.  
  34.     NOTES
  35.     The lock must be freed with ReleaseSemaphore().
  36.  
  37.     EXAMPLE
  38.  
  39.     BUGS
  40.  
  41.     SEE ALSO
  42.     ReleaseSemaphore()
  43.  
  44.     INTERNALS
  45.  
  46.     HISTORY
  47.     29-10-95    digulla automatically created from
  48.                 exec_lib.fd and clib/exec_protos.h
  49.     21-01-96    fleischer implementation
  50.  
  51. *****************************************************************************/
  52. {
  53.     __AROS_FUNC_INIT
  54.     __AROS_BASE_EXT_DECL(struct ExecBase *,SysBase)
  55.  
  56.     ULONG ret=0;
  57.  
  58.     /* Arbitrate for semaphore nesting count and owner fields */
  59.     Forbid();
  60.  
  61.     /* If the semaphore is free or the user is the current task */
  62.     if(!sigSem->ss_NestCount||sigSem->ss_Owner==SysBase->ThisTask)
  63.     {
  64.     /* Get an exclusive lock on it */
  65.     ObtainSemaphore(sigSem);
  66.  
  67.     /* And return true */
  68.     ret=1;
  69.     }
  70.  
  71.     /* All done */
  72.     Permit();
  73.     return ret;
  74.  
  75.     __AROS_FUNC_EXIT
  76. } /* AttemptSemaphore */
  77.  
  78.