os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfmutex.c
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 
    24 
    25 #ifdef __cplusplus
    26 extern "C" {
    27 #endif
    28 
    29 
    30 #include <pthread.h>
    31 #include <errno.h>
    32 #include <stdlib.h>
    33 
    34 #include "owfmemory.h"
    35 #include "owfmutex.h"
    36 
    37 
    38 
    39 #define MUTEX(x)        (pthread_mutex_t*)(*x)
    40 
    41 OWF_API_CALL OWFint
    42 OWF_Mutex_Init(OWF_MUTEX* mutex)
    43 {
    44     if (!mutex)
    45     {
    46         return EINVAL;
    47     }
    48 
    49     *mutex = xalloc(1, sizeof(pthread_mutex_t));
    50     if (!*mutex)
    51     {
    52         return ENOMEM;
    53     }
    54     return pthread_mutex_init(MUTEX(mutex), NULL);
    55 }
    56 
    57 OWF_API_CALL OWFint
    58 OWF_Mutex_Destroy(OWF_MUTEX* mutex)
    59 {
    60     OWFint             err = EINVAL;
    61 
    62     if (!mutex)
    63     {
    64         return EINVAL;
    65     }
    66 
    67     if (*mutex)
    68     {
    69         err = pthread_mutex_destroy(MUTEX(mutex));
    70         xfree(*mutex);
    71         *mutex = NULL;
    72     }
    73     return err;
    74 }
    75 
    76 OWF_API_CALL OWFint
    77 OWF_Mutex_Lock(OWF_MUTEX* mutex)
    78 {
    79     if (!(mutex && *mutex))
    80     {
    81         return EINVAL;
    82     }
    83 
    84     return pthread_mutex_lock(MUTEX(mutex));
    85 }
    86 
    87 OWF_API_CALL OWFint
    88 OWF_Mutex_Unlock(OWF_MUTEX* mutex)
    89 {
    90     if (!(mutex && *mutex))
    91     {
    92         return EINVAL;
    93     }
    94     return pthread_mutex_unlock(MUTEX(mutex));
    95 }
    96 
    97 #ifdef __cplusplus
    98 }
    99 #endif
   100