diff options
| author | Paul Eggert | 2021-10-10 13:59:16 -0700 |
|---|---|---|
| committer | Paul Eggert | 2021-10-10 14:00:26 -0700 |
| commit | 96278de8ac2166c37925f2dfbc0eeb6d368142b9 (patch) | |
| tree | 566142705adf60d95c200aa188e51466d2504c94 /src/process.c | |
| parent | 575e626105b506b008eb9b0a03bb27aeecee54d4 (diff) | |
| download | emacs-96278de8ac2166c37925f2dfbc0eeb6d368142b9.tar.gz emacs-96278de8ac2166c37925f2dfbc0eeb6d368142b9.zip | |
New function num-processors
This addresses a FIXME comment in lisp/emacs-lisp/comp.el,
relating to the number of subsidiary processes used by
comp-run-async-workers in native compilation.
* admin/merge-gnulib (GNULIB_MODULES): Add nproc.
* doc/lispref/processes.texi (Process Information), etc/NEWS:
Document num-processors.
* lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
* lib/nproc.c, lib/nproc.h, m4/nproc.m4:
New files, copied from Gnulib by admin/merge-gnulib.
* lisp/emacs-lisp/comp.el (w32-get-nproc): Remove decl.
(comp-effective-async-max-jobs): Use num-processors.
* src/process.c: Include nproc.h.
(Fnum_processors): New function.
(syms_of_process): Define ‘all’, ‘current’, ‘num-processors’.
* src/w32proc.c (Fw32_get_nproc): Add FIXME comment.
* test/src/process-tests.el (process-num-processors): New test.
Diffstat (limited to 'src/process.c')
| -rw-r--r-- | src/process.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/process.c b/src/process.c index 221d4c7f6c3..746cdc0428a 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -90,6 +90,7 @@ static struct rlimit nofile_limit; | |||
| 90 | 90 | ||
| 91 | #include <c-ctype.h> | 91 | #include <c-ctype.h> |
| 92 | #include <flexmember.h> | 92 | #include <flexmember.h> |
| 93 | #include <nproc.h> | ||
| 93 | #include <sig2str.h> | 94 | #include <sig2str.h> |
| 94 | #include <verify.h> | 95 | #include <verify.h> |
| 95 | 96 | ||
| @@ -8212,6 +8213,20 @@ integer or floating point values. | |||
| 8212 | return system_process_attributes (pid); | 8213 | return system_process_attributes (pid); |
| 8213 | } | 8214 | } |
| 8214 | 8215 | ||
| 8216 | DEFUN ("num-processors", Fnum_processors, Snum_processors, 0, 1, 0, | ||
| 8217 | doc: /* Return the number of processors, a positive integer. | ||
| 8218 | Each usable thread execution unit counts as a processor. | ||
| 8219 | By default, count the number of available processors, | ||
| 8220 | overridable via the OMP_NUM_THREADS environment variable. | ||
| 8221 | If optional argument QUERY is `current', ignore OMP_NUM_THREADS. | ||
| 8222 | If QUERY is `all', also count processors not available. */) | ||
| 8223 | (Lisp_Object query) | ||
| 8224 | { | ||
| 8225 | return make_uint (num_processors (EQ (query, Qall) ? NPROC_ALL | ||
| 8226 | : EQ (query, Qcurrent) ? NPROC_CURRENT | ||
| 8227 | : NPROC_CURRENT_OVERRIDABLE)); | ||
| 8228 | } | ||
| 8229 | |||
| 8215 | #ifdef subprocesses | 8230 | #ifdef subprocesses |
| 8216 | /* Arrange to catch SIGCHLD if this hasn't already been arranged. | 8231 | /* Arrange to catch SIGCHLD if this hasn't already been arranged. |
| 8217 | Invoke this after init_process_emacs, and after glib and/or GNUstep | 8232 | Invoke this after init_process_emacs, and after glib and/or GNUstep |
| @@ -8472,6 +8487,8 @@ syms_of_process (void) | |||
| 8472 | DEFSYM (Qpcpu, "pcpu"); | 8487 | DEFSYM (Qpcpu, "pcpu"); |
| 8473 | DEFSYM (Qpmem, "pmem"); | 8488 | DEFSYM (Qpmem, "pmem"); |
| 8474 | DEFSYM (Qargs, "args"); | 8489 | DEFSYM (Qargs, "args"); |
| 8490 | DEFSYM (Qall, "all"); | ||
| 8491 | DEFSYM (Qcurrent, "current"); | ||
| 8475 | 8492 | ||
| 8476 | DEFVAR_BOOL ("delete-exited-processes", delete_exited_processes, | 8493 | DEFVAR_BOOL ("delete-exited-processes", delete_exited_processes, |
| 8477 | doc: /* Non-nil means delete processes immediately when they exit. | 8494 | doc: /* Non-nil means delete processes immediately when they exit. |
| @@ -8633,4 +8650,5 @@ amounts of data in one go. */); | |||
| 8633 | defsubr (&Sprocess_inherit_coding_system_flag); | 8650 | defsubr (&Sprocess_inherit_coding_system_flag); |
| 8634 | defsubr (&Slist_system_processes); | 8651 | defsubr (&Slist_system_processes); |
| 8635 | defsubr (&Sprocess_attributes); | 8652 | defsubr (&Sprocess_attributes); |
| 8653 | defsubr (&Snum_processors); | ||
| 8636 | } | 8654 | } |