os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfthread.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 #ifdef __cplusplus
    24 extern "C" {
    25 #endif
    26 
    27 #include <errno.h>
    28 #include <pthread.h>
    29 #include <sys/time.h>
    30 #include <unistd.h>
    31 #include <signal.h>
    32 
    33 #ifndef _XOPEN_SOURCE
    34 #define LIPLAP
    35 #define _XOPEN_SOURCE 1 /* nanosleep */
    36 #endif
    37 
    38 #include <time.h>
    39 
    40 #ifdef LIPLAP
    41 #undef _XOPEN_SOURCE
    42 #endif
    43 
    44 #include "owfthread.h"
    45 #include "owfmemory.h"
    46 #include "owftypes.h"
    47 
    48 OWF_API_CALL void
    49 OWF_Thread_Destroy(OWF_THREAD thread)
    50 {
    51     if (thread)
    52     {
    53         OWF_Thread_Join(thread, NULL);
    54         xfree(thread);
    55     }
    56 }
    57 
    58 OWF_API_CALL OWF_THREAD
    59 OWF_Thread_Create(void* (*threadfunc)(void*), void* data)
    60 {
    61     pthread_t*              handle;
    62 
    63     handle = (pthread_t*)xalloc(sizeof(pthread_t), 1);
    64     if (!handle)
    65     {
    66         return NULL;
    67     }
    68 
    69     if (pthread_create(handle, NULL, threadfunc, data))
    70     {
    71         xfree(handle);
    72         return NULL;
    73     }
    74 
    75     return (OWF_THREAD) handle;
    76 }
    77 
    78 OWF_API_CALL OWFint
    79 OWF_Thread_Join(OWF_THREAD thread, void** retval)
    80 {
    81     OWFint          ret = EINVAL;
    82 
    83     if (!thread)
    84     {
    85         return ret;
    86     }
    87     ret = (int) pthread_join(*(pthread_t*) thread, retval);
    88     return ret;
    89 }
    90 
    91 OWF_API_CALL OWFint
    92 OWF_Thread_Cancel(OWF_THREAD thread)
    93 {
    94 	(void)thread;
    95 	return EINVAL;
    96 }
    97 
    98 
    99 OWF_API_CALL void
   100 OWF_Thread_Exit(void* retval)
   101 {
   102     pthread_exit(retval);
   103 }
   104 
   105 OWF_API_CALL void
   106 OWF_Thread_MicroSleep(OWFuint32 usecs)
   107 {
   108 #if _POSIX_C_SOURCE >= 199309L
   109     struct timespec ts;
   110     ts.tv_sec = usecs / 1000000;
   111     ts.tv_nsec = (usecs % 1000000) * 1000;
   112     nanosleep(&ts, NULL);
   113 #else
   114     usleep(usecs);
   115 #endif
   116 }
   117 
   118 OWF_API_CALL void
   119 OWF_Thread_Sleep(OWFuint32 secs)
   120 {
   121     sleep(secs);
   122 }
   123 
   124 
   125 #ifdef __cplusplus
   126 }
   127 #endif