os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfsemaphore.c
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfsemaphore.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,90 @@
     1.4 +/* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 + *
     1.6 + * Permission is hereby granted, free of charge, to any person obtaining a
     1.7 + * copy of this software and/or associated documentation files (the
     1.8 + * "Materials"), to deal in the Materials without restriction, including
     1.9 + * without limitation the rights to use, copy, modify, merge, publish,
    1.10 + * distribute, sublicense, and/or sell copies of the Materials, and to
    1.11 + * permit persons to whom the Materials are furnished to do so, subject to
    1.12 + * the following conditions:
    1.13 + * 
    1.14 + * The above copyright notice and this permission notice shall be included
    1.15 + * in all copies or substantial portions of the Materials.
    1.16 + * 
    1.17 + * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    1.18 + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    1.19 + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    1.20 + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    1.21 + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    1.22 + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    1.23 + * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
    1.24 + */
    1.25 +
    1.26 +#include <errno.h>
    1.27 +#include <time.h>
    1.28 +#include <semaphore.h>
    1.29 +#include <stdlib.h>
    1.30 +
    1.31 +#include "owfsemaphore.h"
    1.32 +#include "owfmemory.h"
    1.33 +
    1.34 +#define SEM(x)          (sem_t*)(*x)
    1.35 +
    1.36 +OWF_API_CALL OWFint
    1.37 +OWF_Semaphore_Init(OWF_SEMAPHORE* sem, OWFint val)
    1.38 +{
    1.39 +    *sem = xalloc(1, sizeof(sem_t));
    1.40 +    if (!*sem) {
    1.41 +        return ENOMEM;
    1.42 +    }
    1.43 +    return sem_init(SEM(sem), 0, val);
    1.44 +}
    1.45 +
    1.46 +OWF_API_CALL OWFint
    1.47 +OWF_Semaphore_Wait(OWF_SEMAPHORE* sem)
    1.48 +{
    1.49 +    if (!*sem) {
    1.50 +        return EINVAL;
    1.51 +    }
    1.52 +    return sem_wait(SEM(sem));
    1.53 +}
    1.54 +
    1.55 +OWF_API_CALL OWFint
    1.56 +OWF_Semaphore_TryWait(OWF_SEMAPHORE* sem)
    1.57 +{
    1.58 +    if (!*sem) {
    1.59 +        return EINVAL;
    1.60 +    }
    1.61 +    return sem_trywait(SEM(sem));
    1.62 +}
    1.63 +
    1.64 +OWF_API_CALL void
    1.65 +OWF_Semaphore_Post(OWF_SEMAPHORE* sem)
    1.66 +{
    1.67 +    if (!*sem) {
    1.68 +        return;
    1.69 +    }
    1.70 +    sem_post(SEM(sem));
    1.71 +}
    1.72 +
    1.73 +OWF_API_CALL OWFint
    1.74 +OWF_Semaphore_GetValue(OWF_SEMAPHORE* sem, OWFint* val)
    1.75 +{
    1.76 +    if (!*sem) {
    1.77 +        return EINVAL;
    1.78 +    }
    1.79 +    return sem_getvalue(SEM(sem), (int *)val);
    1.80 +}
    1.81 +
    1.82 +OWF_API_CALL OWFint
    1.83 +OWF_Semaphore_Destroy(OWF_SEMAPHORE* sem)
    1.84 +{
    1.85 +    OWFint             err = EINVAL;
    1.86 +
    1.87 +    if (*sem) {
    1.88 +        err = sem_destroy(SEM(sem));
    1.89 +        xfree(*sem);
    1.90 +        *sem = NULL;
    1.91 +    }
    1.92 +    return err;
    1.93 +}