Merge remote-tracking branch 'redux/master' into sh4-pool
[tamarin-stm.git] / platform / symbian / symbian-platform.h
blobd9b2a2d3515f10b45a4f211541af058165a4f017
1 /* -*- Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 /* vi: set ts=4 sw=4 expandtab: (add to ~/.vimrc: set modeline modelines=5) */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is [Open Source Virtual Machine.].
18 * The Initial Developer of the Original Code is
19 * Adobe System Incorporated.
20 * Portions created by the Initial Developer are Copyright (C) 1993-2006
21 * the Initial Developer. All Rights Reserved.
23 * Contributor(s):
24 * Adobe AS3 Team
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef __avmplus_symbian_platform__
41 #define __avmplus_symbian_platform__
43 #define VMPI_memcpy ::memcpy
44 #define VMPI_memset ::memset
45 #define VMPI_memcmp ::memcmp
46 #define VMPI_memmove ::memmove
47 #define VMPI_memchr ::memchr
48 #define VMPI_strcmp ::strcmp
49 #define VMPI_strcat ::strcat
50 #define VMPI_strchr ::strchr
51 //#define VMPI_strrchr ::strrchr not called by avm
52 #define VMPI_strcpy ::strcpy
53 #define VMPI_strlen ::strlen
54 #define VMPI_strncat ::strncat
55 #define VMPI_strncmp ::strncmp
56 #define VMPI_strncpy ::strncpy
57 #define VMPI_strtol ::strtol
58 #define VMPI_strstr ::strstr
59 #define VMPI_sprintf ::sprintf
60 #define VMPI_snprintf ::snprintf
61 #define VMPI_vsnprintf ::vsnprintf
62 //#define VMPI_sscanf ::sscanf not called by avm
63 //#define VMPI_atoi ::atoi not called by avm
64 #define VMPI_tolower ::tolower
65 #define VMPI_islower ::islower
66 #define VMPI_toupper ::toupper
67 #define VMPI_isupper ::isupper
68 #define VMPI_isdigit ::isdigit
69 #define VMPI_isalnum ::isalnum
70 #define VMPI_isxdigit ::isxdigit
71 #define VMPI_isspace ::isspace
72 #define VMPI_isgraph ::isgraph
73 #define VMPI_isprint ::isprint
74 #define VMPI_ispunct ::ispunct
75 #define VMPI_iscntrl ::iscntrl
76 #define VMPI_isalpha ::isalpha
77 #define VMPI_abort ::abort
78 #define VMPI_exit ::exit
80 // Set up a jmp_buf suitable for VMPI_longjmpNoUnwind.
81 #define VMPI_setjmpNoUnwind ::setjmp
83 // Jump to an active jmp_buf that was set up by VMPI_setjmpNoUnwind.
84 // Under no circumstances may C++ destructors be unwound during the
85 // jump (MSVC likes to do this by default).
86 #define VMPI_longjmpNoUnwind ::longjmp
88 #include <stddef.h>
89 #include <string.h>
90 #include <stdio.h>
91 #include <stdlib.h>
92 #include <stdarg.h>
93 #include <math.h>
95 #include <ctype.h>
96 #include <limits.h>
98 #include <inttypes.h>
99 #include <e32std.h>
100 #include <e32cmn.h>
102 #include <setjmp.h> // for OOM.h
103 #include <pthread.h>
104 #include <new> // for std::bad_alloc definition in GCGlobalNew.h
106 #define REALLY_INLINE inline
108 #ifdef __WINSCW__
109 #define DISABLE_STATIC_PCRECONTEXT
110 #undef _WIN32
111 #undef __MWERKS__
112 #endif
114 #ifdef MMGC_OVERRIDE_GLOBAL_NEW
115 #error "configuration not supported"
116 #endif
118 #if defined(__ARMCC__)
119 #define AVMPLUS_ALIGN8(type) type __attribute__ ((aligned (8)))
120 #define AVMPLUS_ALIGN16(type) type __attribute__ ((aligned (16)))
121 #else
122 // @todo implement me
123 #define AVMPLUS_ALIGN8(type) type
124 #define AVMPLUS_ALIGN16(type) type
125 #endif
127 typedef pthread_t vmpi_thread_t;
130 * Type defintion for an opaque data type representing platform-defined spin lock
131 * @see VMPI_lockInit(), VMPI_lockAcquire()
133 struct vmpi_spin_lock_t
135 // Looks like Symbian SDK does not support pthread spinlock.
136 // Using pthread_mutex for now (unfortunate since it's usually more expensive).
137 volatile pthread_mutex_t lock;
140 REALLY_INLINE void VMPI_lockInit(vmpi_spin_lock_t* lock)
142 pthread_mutex_init((pthread_mutex_t*)&lock->lock, 0);
145 REALLY_INLINE void VMPI_lockDestroy(vmpi_spin_lock_t *lock)
147 // Avm can call VMPI_lockDestroy before calling VMPI_lockRelease.
148 if(pthread_mutex_trylock((pthread_mutex_t*)&lock->lock) == EBUSY)
150 pthread_mutex_unlock((pthread_mutex_t*)&lock->lock);
152 pthread_mutex_destroy((pthread_mutex_t*)&lock->lock);
155 REALLY_INLINE bool VMPI_lockAcquire(vmpi_spin_lock_t *lock)
157 // It's allowed that different threads try to lock the same lock.
158 int ret = 0;
159 int counter = 0;
160 while (true)
162 ret = pthread_mutex_trylock( (pthread_mutex_t*)&lock->lock );
163 if(ret == 0 || ret != EBUSY) // some bad error
164 break;
165 counter = (counter++) & 63;
166 if(counter == 0)
167 sched_yield();
169 return ret == 0;
172 REALLY_INLINE bool VMPI_lockRelease(vmpi_spin_lock_t *lock)
174 return pthread_mutex_unlock((pthread_mutex_t*)&lock->lock) == 0;
177 REALLY_INLINE bool VMPI_lockTestAndAcquire(vmpi_spin_lock_t *lock)
179 return pthread_mutex_trylock((pthread_mutex_t*)&lock->lock) == 0;
182 #define EMULATE_ATOMICS_WITH_PTHREAD_MUTEX
184 #include "../VMPI/ThreadsPosix-inlines.h"
186 #endif // __avmplus_symbian_platform__