General Info

Interface: Semaphore
Files: lib/semaphore.h
Last change: 23/12/2001
Author: Luiz Henrique Shigunov
Description
Structures
Functions
  • 0x00 - Destroy - Destroy a semaphore
  • 0x01 - Init - Initialize a semaphore
  • 0x02 - P - Lock a semaphore
  • 0x03 - TryP - Try to lock a semaphore
  • 0x04 - V - Unlock a semaphore
  • Description

    This page describes Semaphore user interface.

    Semaphores are usually used to control the use of shared resources.

    Structures

    typedef struct {
        int count;
        unsigned int data[3];
    } Semaphore;
    

    count is the semaphore count and data are specific data and must be initialized with Init.

    0x00 - Destroy

    Syntax

    int Destroy(Semaphore *s);

    Description

    This function destroys semaphore s, freeing its resources.

    The semaphore can't be in use.

    Return value

    0x01 - Init

    Syntax

    int Init(Semaphore *s, int value, int prop);

    Description

    This function initializes semaphore s with count value and properties prop.

    prop isn't used yet.

    Return value

    0x02 - P

    Syntax

    int P(Semaphore *s);

    Description

    This function locks semaphore s.

    If the semaphore count is less or equal to 0, P blocks the calling thread until count becomes positive.

    Return value

    0x03 - TryP

    Syntax

    int TryP(Semaphore *s);

    Description

    This functions tries to lock semaphore s.

    It behaves identically to P, but returns an error if the thread would block.

    Return value

    0x04 - V

    Syntax

    int V(Semaphore *s);

    Description

    This function unlocks semaphore s.

    Return value