author | Matt Plumtree <matt.plumtree@nokia.com> |
Fri, 27 Aug 2010 11:42:02 +0100 | |
branch | bug235_bringup_0 |
changeset 6 | f62733cff1a5 |
child 10 | cd3ce1b777ef |
permissions | -rw-r--r-- |
6
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
1 |
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
2 |
// All rights reserved. |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
3 |
// This component and the accompanying materials are made available |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
4 |
// under the terms of "Eclipse Public License v1.0" |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
5 |
// which accompanies this distribution, and is available |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
7 |
// |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
8 |
// Initial Contributors: |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
9 |
// Nokia Corporation - initial contribution. |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
10 |
// |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
11 |
// Contributors: |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
12 |
// |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
13 |
// Description: |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
14 |
// Cross platform threading support library |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
15 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
16 |
#include "platformthreading.h" |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
17 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
18 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
19 |
#include <windows.h> |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
20 |
#include <WinBase.h> |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
21 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
22 |
#include <unistd.h> |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
23 |
#include <time.h> |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
24 |
#include <signal.h> |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
25 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
26 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
27 |
#include <stdio.h> |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
28 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
29 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
30 |
#ifdef __GNUG__ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
31 |
static void CALLBACK default_interrupt_handler(ULONG_PTR) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
32 |
#else // MSVC |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
33 |
static VOID CALLBACK default_interrupt_handler(__in ULONG_PTR) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
34 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
35 |
#else // LINUX |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
36 |
static void default_interrupt_handler(int) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
37 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
38 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
39 |
// does nothing |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
40 |
; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
41 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
42 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
43 |
namespace Psu |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
44 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
45 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
46 |
#ifndef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
47 |
const int MicrosecsInMillisec = 1000; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
48 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
49 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
50 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
51 |
int platform_create_simple_thread(PLATFORM_THREAD_T * pThreadHandle, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
52 |
PLATFORM_THREADFUNC pFunc, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
53 |
void * param) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
54 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
55 |
int |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
56 |
rv = 0; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
57 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
58 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
59 |
DWORD |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
60 |
threadId, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
61 |
stackSize = 0, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
62 |
creationFlags = 0; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
63 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
64 |
PLATFORM_THREAD_T |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
65 |
tmp = CreateThread(NULL, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
66 |
stackSize, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
67 |
pFunc, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
68 |
param, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
69 |
creationFlags, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
70 |
&threadId); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
71 |
if (tmp == NULL) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
72 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
73 |
rv = GetLastError(); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
74 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
75 |
else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
76 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
77 |
*pThreadHandle = tmp; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
78 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
79 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
80 |
rv = pthread_create(pThreadHandle, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
81 |
0, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
82 |
pFunc, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
83 |
param); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
84 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
85 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
86 |
return rv; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
87 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
88 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
89 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
90 |
void platform_release_thread(PLATFORM_THREAD_T threadHandle) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
91 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
92 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
93 |
CloseHandle(threadHandle); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
94 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
95 |
pthread_detach(threadHandle); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
96 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
97 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
98 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
99 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
100 |
STATUS_T platform_join_thread(PLATFORM_THREAD_T threadHandle) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
101 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
102 |
STATUS_T retVal; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
103 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
104 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
105 |
retVal = WaitForSingleObject(threadHandle,INFINITE); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
106 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
107 |
retVal = pthread_join(threadHandle, NULL); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
108 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
109 |
return retVal; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
110 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
111 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
112 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
113 |
void platform_mutex_init(PLATFORM_MUTEX_T * pMutex) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
114 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
115 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
116 |
InitializeCriticalSection(pMutex); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
117 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
118 |
pthread_mutex_init(pMutex, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
119 |
0); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
120 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
121 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
122 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
123 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
124 |
void platform_mutex_destroy(PLATFORM_MUTEX_T * pMutex) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
125 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
126 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
127 |
DeleteCriticalSection(pMutex); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
128 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
129 |
pthread_mutex_destroy(pMutex); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
130 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
131 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
132 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
133 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
134 |
void platform_mutex_lock(PLATFORM_MUTEX_T * pMutex) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
135 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
136 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
137 |
EnterCriticalSection(pMutex); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
138 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
139 |
pthread_mutex_lock(pMutex); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
140 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
141 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
142 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
143 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
144 |
void platform_mutex_unlock(PLATFORM_MUTEX_T * pMutex) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
145 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
146 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
147 |
LeaveCriticalSection(pMutex); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
148 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
149 |
pthread_mutex_unlock(pMutex); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
150 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
151 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
152 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
153 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
154 |
void platform_sleep(int millisecs) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
155 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
156 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
157 |
Sleep(millisecs); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
158 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
159 |
usleep(millisecs * MicrosecsInMillisec); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
160 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
161 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
162 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
163 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
164 |
STATUS_T platform_create_semaphore(PLATFORM_SEMAPHORE_T& semHandle, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
165 |
int initialCount,int maximumCount) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
166 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
167 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
168 |
STATUS_T rv =0; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
169 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
170 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
171 |
PLATFORM_SEMAPHORE_T |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
172 |
tmp = CreateSemaphore(NULL, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
173 |
initialCount, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
174 |
maximumCount, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
175 |
NULL); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
176 |
if (tmp == NULL) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
177 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
178 |
rv = GetLastError(); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
179 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
180 |
else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
181 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
182 |
semHandle = tmp; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
183 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
184 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
185 |
rv = sem_init(&semHandle, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
186 |
0, |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
187 |
initialCount); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
188 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
189 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
190 |
return rv; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
191 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
192 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
193 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
194 |
STATUS_T platform_wait_for_signal(PLATFORM_SEMAPHORE_T& semHandle) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
195 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
196 |
STATUS_T retVal; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
197 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
198 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
199 |
retVal = WaitForSingleObject(semHandle, INFINITE); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
200 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
201 |
retVal = sem_wait(&semHandle); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
202 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
203 |
return retVal; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
204 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
205 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
206 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
207 |
void platform_signal_semaphore(PLATFORM_SEMAPHORE_T& semHandle) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
208 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
209 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
210 |
ReleaseSemaphore(semHandle, 1, NULL); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
211 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
212 |
sem_post(&semHandle); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
213 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
214 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
215 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
216 |
void platform_release_semaphore(PLATFORM_SEMAPHORE_T& semHandle) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
217 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
218 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
219 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
220 |
CloseHandle(semHandle); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
221 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
222 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
223 |
sem_destroy(&semHandle); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
224 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
225 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
226 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
227 |
int32_t platform_interruptable_sleep(int64_t length) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
228 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
229 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
230 |
return SleepEx(static_cast<DWORD>(length), TRUE); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
231 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
232 |
struct timespec req = {0}; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
233 |
time_t sec = (int)(length/1000); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
234 |
length = length - (sec*1000); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
235 |
req.tv_sec = sec; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
236 |
req.tv_nsec = length*1000000L; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
237 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
238 |
int ret = nanosleep(&req, NULL); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
239 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
240 |
return ret; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
241 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
242 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
243 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
244 |
bool platform_interrupt_sleep(PLATFORM_THREAD_T handle) |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
245 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
246 |
#ifdef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
247 |
int32_t result = QueueUserAPC(default_interrupt_handler, handle, 0); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
248 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
249 |
return (result!=0); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
250 |
#else |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
251 |
return (0 == pthread_kill(handle, SIGUSR1)); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
252 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
253 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
254 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
255 |
#ifndef WIN32 |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
256 |
SignalUSR1Handler SignalUSR1Handler::instance; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
257 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
258 |
SignalUSR1Handler::SignalUSR1Handler() |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
259 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
260 |
//sa = {0}, old = {0}; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
261 |
sa.sa_handler = &default_interrupt_handler; |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
262 |
sigaction(SIGUSR1, &sa, &old); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
263 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
264 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
265 |
SignalUSR1Handler::~SignalUSR1Handler() |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
266 |
{ |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
267 |
sigaction(SIGUSR1, &old, NULL); |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
268 |
} |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
269 |
#endif |
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
270 |
|
f62733cff1a5
Bug 235 Add cross platform host thread adapter library. Builds for TOOLS2 platform (GCC).
Matt Plumtree <matt.plumtree@nokia.com>
parents:
diff
changeset
|
271 |
} |