os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfthread.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/owfthread.c	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,127 @@
     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 +#ifdef __cplusplus
    1.27 +extern "C" {
    1.28 +#endif
    1.29 +
    1.30 +#include <errno.h>
    1.31 +#include <pthread.h>
    1.32 +#include <sys/time.h>
    1.33 +#include <unistd.h>
    1.34 +#include <signal.h>
    1.35 +
    1.36 +#ifndef _XOPEN_SOURCE
    1.37 +#define LIPLAP
    1.38 +#define _XOPEN_SOURCE 1 /* nanosleep */
    1.39 +#endif
    1.40 +
    1.41 +#include <time.h>
    1.42 +
    1.43 +#ifdef LIPLAP
    1.44 +#undef _XOPEN_SOURCE
    1.45 +#endif
    1.46 +
    1.47 +#include "owfthread.h"
    1.48 +#include "owfmemory.h"
    1.49 +#include "owftypes.h"
    1.50 +
    1.51 +OWF_API_CALL void
    1.52 +OWF_Thread_Destroy(OWF_THREAD thread)
    1.53 +{
    1.54 +    if (thread)
    1.55 +    {
    1.56 +        OWF_Thread_Join(thread, NULL);
    1.57 +        xfree(thread);
    1.58 +    }
    1.59 +}
    1.60 +
    1.61 +OWF_API_CALL OWF_THREAD
    1.62 +OWF_Thread_Create(void* (*threadfunc)(void*), void* data)
    1.63 +{
    1.64 +    pthread_t*              handle;
    1.65 +
    1.66 +    handle = (pthread_t*)xalloc(sizeof(pthread_t), 1);
    1.67 +    if (!handle)
    1.68 +    {
    1.69 +        return NULL;
    1.70 +    }
    1.71 +
    1.72 +    if (pthread_create(handle, NULL, threadfunc, data))
    1.73 +    {
    1.74 +        xfree(handle);
    1.75 +        return NULL;
    1.76 +    }
    1.77 +
    1.78 +    return (OWF_THREAD) handle;
    1.79 +}
    1.80 +
    1.81 +OWF_API_CALL OWFint
    1.82 +OWF_Thread_Join(OWF_THREAD thread, void** retval)
    1.83 +{
    1.84 +    OWFint          ret = EINVAL;
    1.85 +
    1.86 +    if (!thread)
    1.87 +    {
    1.88 +        return ret;
    1.89 +    }
    1.90 +    ret = (int) pthread_join(*(pthread_t*) thread, retval);
    1.91 +    return ret;
    1.92 +}
    1.93 +
    1.94 +OWF_API_CALL OWFint
    1.95 +OWF_Thread_Cancel(OWF_THREAD thread)
    1.96 +{
    1.97 +	(void)thread;
    1.98 +	return EINVAL;
    1.99 +}
   1.100 +
   1.101 +
   1.102 +OWF_API_CALL void
   1.103 +OWF_Thread_Exit(void* retval)
   1.104 +{
   1.105 +    pthread_exit(retval);
   1.106 +}
   1.107 +
   1.108 +OWF_API_CALL void
   1.109 +OWF_Thread_MicroSleep(OWFuint32 usecs)
   1.110 +{
   1.111 +#if _POSIX_C_SOURCE >= 199309L
   1.112 +    struct timespec ts;
   1.113 +    ts.tv_sec = usecs / 1000000;
   1.114 +    ts.tv_nsec = (usecs % 1000000) * 1000;
   1.115 +    nanosleep(&ts, NULL);
   1.116 +#else
   1.117 +    usleep(usecs);
   1.118 +#endif
   1.119 +}
   1.120 +
   1.121 +OWF_API_CALL void
   1.122 +OWF_Thread_Sleep(OWFuint32 secs)
   1.123 +{
   1.124 +    sleep(secs);
   1.125 +}
   1.126 +
   1.127 +
   1.128 +#ifdef __cplusplus
   1.129 +}
   1.130 +#endif