comparison packages/language/c/libm/current/src/misc/compatmode.cxx @ 0:3111d98ba7b3 ecos-v1_1-release

Initial commit of eCos version 1.1
author jlarmour
date Tue, 11 May 1999 11:16:07 +0000
parents
children 443894e2e912
comparison
equal deleted inserted replaced
-1:000000000000 0:3111d98ba7b3
1 //===========================================================================
2 //
3 // compatmode.cxx
4 //
5 // Compatibility mode setting for Math library
6 //
7 //===========================================================================
8 //####COPYRIGHTBEGIN####
9 //
10 // -------------------------------------------
11 // The contents of this file are subject to the Cygnus eCos Public License
12 // Version 1.0 (the "License"); you may not use this file except in
13 // compliance with the License. You may obtain a copy of the License at
14 // http://sourceware.cygnus.com/ecos
15 //
16 // Software distributed under the License is distributed on an "AS IS"
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
18 // License for the specific language governing rights and limitations under
19 // the License.
20 //
21 // The Original Code is eCos - Embedded Cygnus Operating System, released
22 // September 30, 1998.
23 //
24 // The Initial Developer of the Original Code is Cygnus. Portions created
25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved.
26 // -------------------------------------------
27 //
28 //####COPYRIGHTEND####
29 //===========================================================================
30 //#####DESCRIPTIONBEGIN####
31 //
32 // Author(s): jlarmour@cygnus.co.uk
33 // Contributors: jlarmour@cygnus.co.uk
34 // Date: 1998-02-13
35 // Purpose:
36 // Description: Contains the accessor functions to get and set the standards
37 // compatibility mode of the Math library
38 // Usage:
39 //
40 //####DESCRIPTIONEND####
41 //
42 //===========================================================================
43
44 // CONFIGURATION
45
46 #include <pkgconf/libm.h> // Configuration header
47
48 // Include the Math library?
49 #ifdef CYGPKG_LIBM
50
51 // INCLUDES
52
53 #include <cyg/infra/cyg_type.h> // Common type definitions and support
54 #include <cyg/infra/cyg_trac.h> // Tracing macros
55
56 #include <math.h> // Main header for math library
57
58 #ifdef CYGSEM_LIBM_THREAD_SAFE_COMPAT_MODE
59 # include <cyg/kernel/thread.hxx> // Kernel thread header
60 # include <cyg/kernel/thread.inl> // and its associated inlines
61 # include <cyg/kernel/mutex.hxx> // We need mutexes too
62 #endif
63
64 // GLOBAL VARIABLES
65
66 #ifndef CYGSEM_LIBM_THREAD_SAFE_COMPAT_MODE
67
68 # ifdef CYGSEM_LIBM_COMPAT_IEEE_ONLY
69 Cyg_libm_compat_t cygvar_libm_compat_mode = CYGNUM_LIBM_COMPAT_IEEE;
70 # else
71 Cyg_libm_compat_t cygvar_libm_compat_mode = CYGNUM_LIBM_COMPAT_DEFAULT;
72 # endif
73
74 #else // ifndef CYGSEM_LIBM_THREAD_SAFE_COMPAT_MODE
75
76 static Cyg_Mutex cyg_libm_mode_thread_data_index_mutex;
77 static cyg_count32 cyg_libm_mode_thread_data_index = CYGNUM_KERNEL_THREADS_DATA_MAX;
78
79
80 # if defined(CYGDBG_USE_TRACING) && \
81 defined(CYGNUM_LIBM_COMPATMODE_TRACE_LEVEL)
82 static int libm_compatmode_trace = CYGNUM_LIBM_COMPATMODE_TRACE_LEVEL;
83 # define TL1 (0 < libm_compatmode_trace )
84 # else
85 # define TL1 (0)
86 # endif
87
88 // FUNCTIONS
89
90
91 Cyg_libm_compat_t
92 cyg_libm_get_compat_mode( void )
93 {
94 Cyg_Thread *self = Cyg_Thread::self();
95 CYG_ADDRWORD current_val;
96
97 CYG_REPORT_FUNCNAMETYPE( "Cyg_libm_get_compat_mode", "mode is %d" );
98
99 // First check if this is the first thread to get here, and if so,
100 // initialise the thread data index
101
102 if (cyg_libm_mode_thread_data_index == CYGNUM_KERNEL_THREADS_DATA_MAX)
103 {
104 CYG_TRACE0( TL1, "Index unset, locking mutex to allocate" );
105
106 // Lock mutex and then check again - less overhead for normal
107 // execution path
108 cyg_libm_mode_thread_data_index_mutex.lock();
109
110 if (cyg_libm_mode_thread_data_index == CYGNUM_KERNEL_THREADS_DATA_MAX)
111 {
112 CYG_TRACE0( TL1, "Allocating index" );
113 cyg_libm_mode_thread_data_index = self->new_data_index();
114
115 } // if
116
117 cyg_libm_mode_thread_data_index_mutex.unlock();
118
119 self->set_data( cyg_libm_mode_thread_data_index,
120 CYGNUM_LIBM_COMPAT_DEFAULT );
121
122 // But if we've gone through this, then we know what the mode is!
123 CYG_REPORT_RETVAL( CYGNUM_LIBM_COMPAT_DEFAULT );
124 return CYGNUM_LIBM_COMPAT_DEFAULT;
125 } // if
126
127 CYG_TRACE0( TL1, "Index set, now fetching per-thread data" );
128
129 // If we're here, then the index is set up
130
131 current_val = self->get_data( cyg_libm_mode_thread_data_index );
132
133 // If its at the "default" setting, then return the default
134 if (current_val == CYGNUM_LIBM_COMPAT_UNINIT)
135 {
136 CYG_REPORT_RETVAL( CYGNUM_LIBM_COMPAT_DEFAULT );
137 return CYGNUM_LIBM_COMPAT_DEFAULT;
138 } // if
139
140 CYG_REPORT_RETVAL( current_val );
141 return (Cyg_libm_compat_t) current_val;
142 } // cyg_libm_get_compat_mode()
143
144
145 Cyg_libm_compat_t
146 cyg_libm_set_compat_mode( Cyg_libm_compat_t new_mode )
147 {
148 Cyg_Thread *self = Cyg_Thread::self();
149 CYG_ADDRWORD current_val;
150
151 CYG_REPORT_FUNCNAMETYPE( "Cyg_libm_set_compat_mode", "old mode was %d" );
152 CYG_REPORT_FUNCARG1DV( new_mode );
153
154 // First check if this is the first thread to get here, and if so,
155 // initialise the thread data index
156
157 if (cyg_libm_mode_thread_data_index == CYGNUM_KERNEL_THREADS_DATA_MAX)
158 {
159 CYG_TRACE0( TL1, "Index unset, locking mutex to allocate" );
160
161 // Lock mutex and then check again - less overhead for normal
162 // execution path
163 cyg_libm_mode_thread_data_index_mutex.lock();
164
165 if (cyg_libm_mode_thread_data_index == CYGNUM_KERNEL_THREADS_DATA_MAX)
166 {
167 CYG_TRACE0( TL1, "Allocating index" );
168 cyg_libm_mode_thread_data_index = self->new_data_index();
169
170 } // if
171
172 cyg_libm_mode_thread_data_index_mutex.unlock();
173
174 self->set_data( cyg_libm_mode_thread_data_index,
175 new_mode );
176
177 // But if we've gone through this, then we know what the old mode was!
178
179 CYG_REPORT_RETVAL( CYGNUM_LIBM_COMPAT_UNINIT );
180 return CYGNUM_LIBM_COMPAT_UNINIT;
181
182 } // if
183
184 // If we're here, then the index is set up
185
186 CYG_TRACE0( TL1, "Index set, now fetching per-thread data" );
187
188 current_val = self->get_data( cyg_libm_mode_thread_data_index );
189
190 self->set_data( cyg_libm_mode_thread_data_index,
191 new_mode );
192
193 CYG_REPORT_RETVAL( current_val );
194 return (Cyg_libm_compat_t) current_val;
195
196 } // cyg_libm_set_compat_mode()
197
198 #endif // ifdef CYGSEM_LIBM_THREAD_SAFE_COMPAT_MODE
199
200
201 #endif // ifdef CYGPKG_LIBM
202
203 // EOF compatmode.cxx