aboutsummaryrefslogtreecommitdiff
path: root/liblangdet
diff options
context:
space:
mode:
Diffstat (limited to 'liblangdet')
-rw-r--r--liblangdet/langdet.c3
-rw-r--r--liblangdet/langdet.h2
-rw-r--r--liblangdet/threadpool.c3
3 files changed, 6 insertions, 2 deletions
diff --git a/liblangdet/langdet.c b/liblangdet/langdet.c
index 0fe5433..13a6359 100644
--- a/liblangdet/langdet.c
+++ b/liblangdet/langdet.c
@@ -143,8 +143,7 @@ int langdet_predict(langdet_t *d, const char *text, langdet_result_t *result,
if (!d || !text || !result)
return set_error(err, errlen, "Detector, text, and result must not be NULL");
- if (tp_num_threads() != d->n_threads)
- tp_set_threads(d->n_threads);
+ tp_set_threads(d->n_threads);
int count = 0;
int *ids = langdet_tokenize(d->tokenizer, text, &count);
if (!ids || count < 2) {
diff --git a/liblangdet/langdet.h b/liblangdet/langdet.h
index 22e0b64..d5cb9b3 100644
--- a/liblangdet/langdet.h
+++ b/liblangdet/langdet.h
@@ -28,6 +28,8 @@ typedef struct {
/* Load the model, tokenizer, classifier, and labels from model_dir.
* n_threads is 1..16, or 0 to detect the CPU count and cap it at 16.
+ * On macOS it sets kernel workers; Accelerate manages its own threads.
+ * On Linux it sets OpenBLAS threads; the auxiliary kernel pool stays serial.
* Return NULL on failure. An optional err[errlen] receives a NUL-terminated
* message on failure and is cleared on success. Model-file readers may also
* write diagnostics to stderr. */
diff --git a/liblangdet/threadpool.c b/liblangdet/threadpool.c
index 6cb4252..e0ffbc6 100644
--- a/liblangdet/threadpool.c
+++ b/liblangdet/threadpool.c
@@ -93,6 +93,9 @@ void tp_set_threads(int n) {
n = 1;
#endif
+ if (n == tp.n_threads)
+ return;
+
/* Shutdown existing workers */
if (tp.n_threads > 1) {
pthread_mutex_lock(&tp.mutex);