os/graphics/graphicscomposition/openwfcompositionengine/adaptation/src/Platform/OS/symbian/owfthread.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
 * 
sl@0
     3
 * Permission is hereby granted, free of charge, to any person obtaining a
sl@0
     4
 * copy of this software and/or associated documentation files (the
sl@0
     5
 * "Materials"), to deal in the Materials without restriction, including
sl@0
     6
 * without limitation the rights to use, copy, modify, merge, publish,
sl@0
     7
 * distribute, sublicense, and/or sell copies of the Materials, and to
sl@0
     8
 * permit persons to whom the Materials are furnished to do so, subject to
sl@0
     9
 * the following conditions:
sl@0
    10
 * 
sl@0
    11
 * The above copyright notice and this permission notice shall be included
sl@0
    12
 * in all copies or substantial portions of the Materials.
sl@0
    13
 * 
sl@0
    14
 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
sl@0
    15
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
sl@0
    16
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
sl@0
    17
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
sl@0
    18
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
sl@0
    19
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
sl@0
    20
 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
sl@0
    21
 */
sl@0
    22
sl@0
    23
#ifdef __cplusplus
sl@0
    24
extern "C" {
sl@0
    25
#endif
sl@0
    26
sl@0
    27
#include <errno.h>
sl@0
    28
#include <pthread.h>
sl@0
    29
#include <sys/time.h>
sl@0
    30
#include <unistd.h>
sl@0
    31
#include <signal.h>
sl@0
    32
sl@0
    33
#ifndef _XOPEN_SOURCE
sl@0
    34
#define LIPLAP
sl@0
    35
#define _XOPEN_SOURCE 1 /* nanosleep */
sl@0
    36
#endif
sl@0
    37
sl@0
    38
#include <time.h>
sl@0
    39
sl@0
    40
#ifdef LIPLAP
sl@0
    41
#undef _XOPEN_SOURCE
sl@0
    42
#endif
sl@0
    43
sl@0
    44
#include "owfthread.h"
sl@0
    45
#include "owfmemory.h"
sl@0
    46
#include "owftypes.h"
sl@0
    47
sl@0
    48
OWF_API_CALL void
sl@0
    49
OWF_Thread_Destroy(OWF_THREAD thread)
sl@0
    50
{
sl@0
    51
    if (thread)
sl@0
    52
    {
sl@0
    53
        OWF_Thread_Join(thread, NULL);
sl@0
    54
        xfree(thread);
sl@0
    55
    }
sl@0
    56
}
sl@0
    57
sl@0
    58
OWF_API_CALL OWF_THREAD
sl@0
    59
OWF_Thread_Create(void* (*threadfunc)(void*), void* data)
sl@0
    60
{
sl@0
    61
    pthread_t*              handle;
sl@0
    62
sl@0
    63
    handle = (pthread_t*)xalloc(sizeof(pthread_t), 1);
sl@0
    64
    if (!handle)
sl@0
    65
    {
sl@0
    66
        return NULL;
sl@0
    67
    }
sl@0
    68
sl@0
    69
    if (pthread_create(handle, NULL, threadfunc, data))
sl@0
    70
    {
sl@0
    71
        xfree(handle);
sl@0
    72
        return NULL;
sl@0
    73
    }
sl@0
    74
sl@0
    75
    return (OWF_THREAD) handle;
sl@0
    76
}
sl@0
    77
sl@0
    78
OWF_API_CALL OWFint
sl@0
    79
OWF_Thread_Join(OWF_THREAD thread, void** retval)
sl@0
    80
{
sl@0
    81
    OWFint          ret = EINVAL;
sl@0
    82
sl@0
    83
    if (!thread)
sl@0
    84
    {
sl@0
    85
        return ret;
sl@0
    86
    }
sl@0
    87
    ret = (int) pthread_join(*(pthread_t*) thread, retval);
sl@0
    88
    return ret;
sl@0
    89
}
sl@0
    90
sl@0
    91
OWF_API_CALL OWFint
sl@0
    92
OWF_Thread_Cancel(OWF_THREAD thread)
sl@0
    93
{
sl@0
    94
	(void)thread;
sl@0
    95
	return EINVAL;
sl@0
    96
}
sl@0
    97
sl@0
    98
sl@0
    99
OWF_API_CALL void
sl@0
   100
OWF_Thread_Exit(void* retval)
sl@0
   101
{
sl@0
   102
    pthread_exit(retval);
sl@0
   103
}
sl@0
   104
sl@0
   105
OWF_API_CALL void
sl@0
   106
OWF_Thread_MicroSleep(OWFuint32 usecs)
sl@0
   107
{
sl@0
   108
#if _POSIX_C_SOURCE >= 199309L
sl@0
   109
    struct timespec ts;
sl@0
   110
    ts.tv_sec = usecs / 1000000;
sl@0
   111
    ts.tv_nsec = (usecs % 1000000) * 1000;
sl@0
   112
    nanosleep(&ts, NULL);
sl@0
   113
#else
sl@0
   114
    usleep(usecs);
sl@0
   115
#endif
sl@0
   116
}
sl@0
   117
sl@0
   118
OWF_API_CALL void
sl@0
   119
OWF_Thread_Sleep(OWFuint32 secs)
sl@0
   120
{
sl@0
   121
    sleep(secs);
sl@0
   122
}
sl@0
   123
sl@0
   124
sl@0
   125
#ifdef __cplusplus
sl@0
   126
}
sl@0
   127
#endif