/*
 * Scalos/iconobject.library
 * semaphores.c
 *
 * $VER: semaphores.c 1.0 (31/01/2000)
 * Richard Drummond
 *
 * Support for private signal semaphores
 *
 */

#include <exec/types.h>
#include <exec/memory.h>
#include <exec/semaphores.h>

#include <proto/exec.h>




/*
 * CreateSemaphore()
 *
 * PURPOSE: To allocate and initialize a signal semaphore
 * INPUTS:  None
 * RESULT:  A pointer to an initialized semaphore structure or NULL on
 *          failure
 */

struct SignalSemaphore *
CreateSemaphore( VOID )
{
    struct SignalSemaphore *s;

    if( s = AllocVec( sizeof(struct SignalSemaphore), MEMF_PUBLIC ) )
    {
        InitSemaphore( s );
    }
    return s;
}


/*
 * FreeSemaphore()
 *
 * PURPOSE: To free a previously allocated (private) singal semaphore
 * INPUTS:  s - the semaphore to free
 * RESULTS: None:
 */

VOID
FreeSemaphore( struct SignalSemaphore *s )
{
    Forbid();               /* We don't want to be reschudled */
    ObtainSemaphore( s );   /* Wait until everybody's finished with the semaphore */
    ReleaseSemaphore( s );
    FreeVec( s );           /* Safe to free the memory */
    Permit();
}




