@@ -120,14 +120,8 @@ bool RhConfig::Environment::TryGetStringValue(const char* name, char** value)
120120 return true ;
121121}
122122
123- struct CompilerEmbeddedSettingsBlob
124- {
125- uint32_t Size;
126- char Data[1 ];
127- };
128-
129- extern " C" CompilerEmbeddedSettingsBlob g_compilerEmbeddedSettingsBlob;
130- extern " C" CompilerEmbeddedSettingsBlob g_compilerEmbeddedKnobsBlob;
123+ extern " C" RhConfig::Config g_compilerEmbeddedSettingsBlob;
124+ extern " C" RhConfig::Config g_compilerEmbeddedKnobsBlob;
131125
132126bool RhConfig::ReadConfigValue (_In_z_ const char *name, uint64_t * pValue, bool decimal)
133127{
@@ -136,7 +130,7 @@ bool RhConfig::ReadConfigValue(_In_z_ const char *name, uint64_t* pValue, bool d
136130
137131 // Check the embedded configuration
138132 const char *embeddedValue = nullptr ;
139- if (GetEmbeddedVariable (&g_embeddedSettings, & g_compilerEmbeddedSettingsBlob, name, true , &embeddedValue))
133+ if (GetEmbeddedVariable (&g_compilerEmbeddedSettingsBlob, name, true , &embeddedValue))
140134 {
141135 *pValue = strtoull (embeddedValue, NULL , decimal ? 10 : 16 );
142136 return true ;
@@ -148,7 +142,7 @@ bool RhConfig::ReadConfigValue(_In_z_ const char *name, uint64_t* pValue, bool d
148142bool RhConfig::ReadKnobUInt64Value (_In_z_ const char *name, uint64_t * pValue)
149143{
150144 const char *embeddedValue = nullptr ;
151- if (GetEmbeddedVariable (&g_embeddedKnobs, & g_compilerEmbeddedKnobsBlob, name, false , &embeddedValue))
145+ if (GetEmbeddedVariable (&g_compilerEmbeddedKnobsBlob, name, false , &embeddedValue))
152146 {
153147 *pValue = strtoull (embeddedValue, NULL , 10 );
154148 return true ;
@@ -160,7 +154,7 @@ bool RhConfig::ReadKnobUInt64Value(_In_z_ const char *name, uint64_t* pValue)
160154bool RhConfig::ReadKnobBooleanValue (_In_z_ const char *name, bool * pValue)
161155{
162156 const char *embeddedValue = nullptr ;
163- if (GetEmbeddedVariable (&g_embeddedKnobs, & g_compilerEmbeddedKnobsBlob, name, false , &embeddedValue))
157+ if (GetEmbeddedVariable (&g_compilerEmbeddedKnobsBlob, name, false , &embeddedValue))
164158 {
165159 *pValue = strcmp (embeddedValue, " true" ) == 0 ;
166160 return true ;
@@ -169,29 +163,30 @@ bool RhConfig::ReadKnobBooleanValue(_In_z_ const char *name, bool* pValue)
169163 return false ;
170164}
171165
172- bool RhConfig::GetEmbeddedVariable ( void * volatile * embeddedSettings, void * compilerEmbeddedSettingsBlob, _In_z_ const char * configName, bool caseSensitive, _Out_ const char ** configValue )
166+ char ** RhConfig::GetKnobNames ( )
173167{
174- // Read the config if we haven't yet
175- if (*embeddedSettings == NULL )
176- {
177- ReadEmbeddedSettings (embeddedSettings, compilerEmbeddedSettingsBlob);
178- }
168+ return g_compilerEmbeddedKnobsBlob.GetKeys ();
169+ }
179170
180- // Config wasn't read or reading failed
181- if (*embeddedSettings == CONFIG_INI_NOT_AVAIL)
182- {
183- return false ;
184- }
171+ char ** RhConfig::GetKnobValues ()
172+ {
173+ return g_compilerEmbeddedKnobsBlob.GetValues ();
174+ }
185175
186- const ConfigPair* configPairs = (const ConfigPair*)*embeddedSettings;
176+ uint32_t RhConfig::GetKnobCount ()
177+ {
178+ return g_compilerEmbeddedKnobsBlob.GetCount ();
179+ }
187180
181+ bool RhConfig::GetEmbeddedVariable (Config* config, _In_z_ const char * configName, bool caseSensitive, _Out_ const char ** configValue)
182+ {
188183 // Find the first name which matches
189- for (uint32_t iSettings = 0 ; iSettings < ((CompilerEmbeddedSettingsBlob*)compilerEmbeddedSettingsBlob)-> Size ; iSettings++)
184+ for (uint32_t iSettings = 0 ; iSettings < config-> GetCount () ; iSettings++)
190185 {
191- if ((caseSensitive && strcmp (configName, configPairs[ iSettings]. Key ) == 0 )
192- || (!caseSensitive && _stricmp (configName, configPairs[ iSettings]. Key ) == 0 ))
186+ if ((caseSensitive && strcmp (configName, config-> GetKeyAt ( iSettings) ) == 0 )
187+ || (!caseSensitive && _stricmp (configName, config-> GetKeyAt ( iSettings) ) == 0 ))
193188 {
194- *configValue = configPairs[ iSettings]. Value ;
189+ *configValue = config-> GetValueAt ( iSettings) ;
195190 return true ;
196191 }
197192 }
@@ -200,107 +195,4 @@ bool RhConfig::GetEmbeddedVariable(void *volatile * embeddedSettings, void* comp
200195 return false ;
201196}
202197
203- void RhConfig::ReadEmbeddedSettings (void *volatile * embeddedSettings, void * compilerEmbeddedSettingsBlob)
204- {
205- if (*embeddedSettings == NULL )
206- {
207- uint32_t size = ((CompilerEmbeddedSettingsBlob*)compilerEmbeddedSettingsBlob)->Size ;
208- char * data = ((CompilerEmbeddedSettingsBlob*)compilerEmbeddedSettingsBlob)->Data ;
209-
210- // if reading the file contents failed set embeddedSettings to CONFIG_INI_NOT_AVAIL
211- if (size == 0 )
212- {
213- // only set if another thread hasn't initialized the buffer yet, otherwise ignore and let the first setter win
214- PalInterlockedCompareExchangePointer (embeddedSettings, CONFIG_INI_NOT_AVAIL, NULL );
215-
216- return ;
217- }
218-
219- ConfigPair* iniBuff = new (nothrow) ConfigPair[size];
220- if (iniBuff == NULL )
221- {
222- // only set if another thread hasn't initialized the buffer yet, otherwise ignore and let the first setter win
223- PalInterlockedCompareExchangePointer (embeddedSettings, CONFIG_INI_NOT_AVAIL, NULL );
224-
225- return ;
226- }
227-
228- uint32_t iBuff = 0 ;
229- uint32_t iIniBuff = 0 ;
230- char * currLine;
231-
232- // while we haven't reached the max number of config pairs, or the end of the file, read the next line
233- while (iBuff < size)
234- {
235- currLine = &data[iBuff];
236-
237- // find the end of the line
238- while ((data[iBuff] != ' \0 ' ) && (iBuff < size))
239- iBuff++;
240-
241- // parse the line
242- // only increment iIniBuff if the parsing succeeded otherwise reuse the config struct
243- if (ParseConfigLine (&iniBuff[iIniBuff], currLine))
244- {
245- iIniBuff++;
246- }
247-
248- // advance to the next line;
249- iBuff++;
250- }
251-
252- // if another thread initialized first let the first setter win
253- // delete the iniBuff to avoid leaking memory
254- if (PalInterlockedCompareExchangePointer (embeddedSettings, iniBuff, NULL ) != NULL )
255- {
256- delete[] iniBuff;
257- }
258- }
259-
260- return ;
261- }
262-
263- // Parses one line of config and populates values in the passed in configPair
264- // returns: true if the parsing was successful, false if the parsing failed.
265- // NOTE: if the method fails configPair is left in an uninitialized state
266- bool RhConfig::ParseConfigLine (_Out_ ConfigPair* configPair, _In_z_ const char * line)
267- {
268- uint32_t iLine = 0 ;
269- uint32_t iKey = 0 ;
270- uint32_t iVal = 0 ;
271-
272- // while we haven't reached the end of the key signalled by '=', or the end of the line, or the key maxlen
273- while (line[iLine] != ' =' && line[iLine] != ' \0 ' && iKey < CONFIG_KEY_MAXLEN)
274- {
275- configPair->Key [iKey++] = line[iLine++];
276- }
277-
278- // if the current char is not '=' we reached the key maxlen, or the line ended return false
279- if (line[iLine] != ' =' )
280- {
281- return FALSE ;
282- }
283-
284- configPair->Key [iKey] = ' \0 ' ;
285-
286- // increment to start of the value
287- iLine++;
288-
289- // while we haven't reached the end of the line, or val maxlen
290- while (line[iLine] != ' \0 ' && iVal < CONFIG_VAL_MAXLEN)
291- {
292- configPair->Value [iVal++] = line[iLine++];
293- }
294-
295- // if the current char is not '\0' we didn't reach the end of the line return false
296- if (line[iLine] != ' \0 ' )
297- {
298- return FALSE ;
299- }
300-
301- configPair->Value [iVal] = ' \0 ' ;
302-
303- return TRUE ;
304- }
305-
306198#endif
0 commit comments