os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfsemaphore.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  *
     3  * Permission is hereby granted, free of charge, to any person obtaining a
     4  * copy of this software and/or associated documentation files (the
     5  * "Materials"), to deal in the Materials without restriction, including
     6  * without limitation the rights to use, copy, modify, merge, publish,
     7  * distribute, sublicense, and/or sell copies of the Materials, and to
     8  * permit persons to whom the Materials are furnished to do so, subject to
     9  * the following conditions:
    10  * 
    11  * The above copyright notice and this permission notice shall be included
    12  * in all copies or substantial portions of the Materials.
    13  * 
    14  * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    20  * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
    21  */
    22 
    23 #include <errno.h>
    24 #include <time.h>
    25 #include <semaphore.h>
    26 #include <stdlib.h>
    27 
    28 #include "owfsemaphore.h"
    29 #include "owfmemory.h"
    30 
    31 #define SEM(x)          (sem_t*)(*x)
    32 
    33 OWF_API_CALL OWFint
    34 OWF_Semaphore_Init(OWF_SEMAPHORE* sem, OWFint val)
    35 {
    36     *sem = xalloc(1, sizeof(sem_t));
    37     if (!*sem) {
    38         return ENOMEM;
    39     }
    40     return sem_init(SEM(sem), 0, val);
    41 }
    42 
    43 OWF_API_CALL OWFint
    44 OWF_Semaphore_Wait(OWF_SEMAPHORE* sem)
    45 {
    46     if (!*sem) {
    47         return EINVAL;
    48     }
    49     return sem_wait(SEM(sem));
    50 }
    51 
    52 OWF_API_CALL OWFint
    53 OWF_Semaphore_TryWait(OWF_SEMAPHORE* sem)
    54 {
    55     if (!*sem) {
    56         return EINVAL;
    57     }
    58     return sem_trywait(SEM(sem));
    59 }
    60 
    61 OWF_API_CALL void
    62 OWF_Semaphore_Post(OWF_SEMAPHORE* sem)
    63 {
    64     if (!*sem) {
    65         return;
    66     }
    67     sem_post(SEM(sem));
    68 }
    69 
    70 OWF_API_CALL OWFint
    71 OWF_Semaphore_GetValue(OWF_SEMAPHORE* sem, OWFint* val)
    72 {
    73     if (!*sem) {
    74         return EINVAL;
    75     }
    76     return sem_getvalue(SEM(sem), (int *)val);
    77 }
    78 
    79 OWF_API_CALL OWFint
    80 OWF_Semaphore_Destroy(OWF_SEMAPHORE* sem)
    81 {
    82     OWFint             err = EINVAL;
    83 
    84     if (*sem) {
    85         err = sem_destroy(SEM(sem));
    86         xfree(*sem);
    87         *sem = NULL;
    88     }
    89     return err;
    90 }