mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Merge pull request #130 from prometheus/julius-threadsafe-parser
Make expression parser goroutine-safe.
This commit is contained in:
commit
2310f549dd
|
@ -20,14 +20,16 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NOTE: This parser is non-reentrant due to its dependence on global state.
|
|
||||||
|
|
||||||
// GoLex sadly needs these global variables for storing temporary token/parsing information.
|
// GoLex sadly needs these global variables for storing temporary token/parsing information.
|
||||||
var yylval *yySymType // For storing extra token information, like the contents of a string.
|
var (
|
||||||
var yyline int // Line number within the current file or buffer.
|
yylval *yySymType // For storing extra token information, like the contents of a string.
|
||||||
var yypos int // Character position within the current line.
|
yyline int // Line number within the current file or buffer.
|
||||||
|
yypos int // Character position within the current line.
|
||||||
|
parseMutex sync.Mutex // Mutex protecting the parsing-related global state defined above.
|
||||||
|
)
|
||||||
|
|
||||||
type RulesLexer struct {
|
type RulesLexer struct {
|
||||||
errors []string // Errors encountered during parsing.
|
errors []string // Errors encountered during parsing.
|
||||||
|
@ -58,6 +60,9 @@ func (lexer *RulesLexer) Error(errorStr string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoadFromReader(rulesReader io.Reader, singleExpr bool) (interface{}, error) {
|
func LoadFromReader(rulesReader io.Reader, singleExpr bool) (interface{}, error) {
|
||||||
|
parseMutex.Lock()
|
||||||
|
defer parseMutex.Unlock()
|
||||||
|
|
||||||
yyin = rulesReader
|
yyin = rulesReader
|
||||||
yypos = 1
|
yypos = 1
|
||||||
yyline = 1
|
yyline = 1
|
||||||
|
|
Loading…
Reference in a new issue