os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfmutex.c
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfmutex.c Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,100 @@
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 +
1.27 +
1.28 +#ifdef __cplusplus
1.29 +extern "C" {
1.30 +#endif
1.31 +
1.32 +
1.33 +#include <pthread.h>
1.34 +#include <errno.h>
1.35 +#include <stdlib.h>
1.36 +
1.37 +#include "owfmemory.h"
1.38 +#include "owfmutex.h"
1.39 +
1.40 +
1.41 +
1.42 +#define MUTEX(x) (pthread_mutex_t*)(*x)
1.43 +
1.44 +OWF_API_CALL OWFint
1.45 +OWF_Mutex_Init(OWF_MUTEX* mutex)
1.46 +{
1.47 + if (!mutex)
1.48 + {
1.49 + return EINVAL;
1.50 + }
1.51 +
1.52 + *mutex = xalloc(1, sizeof(pthread_mutex_t));
1.53 + if (!*mutex)
1.54 + {
1.55 + return ENOMEM;
1.56 + }
1.57 + return pthread_mutex_init(MUTEX(mutex), NULL);
1.58 +}
1.59 +
1.60 +OWF_API_CALL OWFint
1.61 +OWF_Mutex_Destroy(OWF_MUTEX* mutex)
1.62 +{
1.63 + OWFint err = EINVAL;
1.64 +
1.65 + if (!mutex)
1.66 + {
1.67 + return EINVAL;
1.68 + }
1.69 +
1.70 + if (*mutex)
1.71 + {
1.72 + err = pthread_mutex_destroy(MUTEX(mutex));
1.73 + xfree(*mutex);
1.74 + *mutex = NULL;
1.75 + }
1.76 + return err;
1.77 +}
1.78 +
1.79 +OWF_API_CALL OWFint
1.80 +OWF_Mutex_Lock(OWF_MUTEX* mutex)
1.81 +{
1.82 + if (!(mutex && *mutex))
1.83 + {
1.84 + return EINVAL;
1.85 + }
1.86 +
1.87 + return pthread_mutex_lock(MUTEX(mutex));
1.88 +}
1.89 +
1.90 +OWF_API_CALL OWFint
1.91 +OWF_Mutex_Unlock(OWF_MUTEX* mutex)
1.92 +{
1.93 + if (!(mutex && *mutex))
1.94 + {
1.95 + return EINVAL;
1.96 + }
1.97 + return pthread_mutex_unlock(MUTEX(mutex));
1.98 +}
1.99 +
1.100 +#ifdef __cplusplus
1.101 +}
1.102 +#endif
1.103 +