From 1764edc3b60a2c9fb210ca74b758f3e8e8a53692 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Tue, 25 May 2021 20:48:22 +0000
Subject: l3kernel (25may21)

git-svn-id: svn://tug.org/texlive/trunk@59345 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/source/latex/l3kernel/l3sys.dtx | 60 ++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)

(limited to 'Master/texmf-dist/source/latex/l3kernel/l3sys.dtx')

diff --git a/Master/texmf-dist/source/latex/l3kernel/l3sys.dtx b/Master/texmf-dist/source/latex/l3kernel/l3sys.dtx
index 6399f57f318..40bb7db644c 100644
--- a/Master/texmf-dist/source/latex/l3kernel/l3sys.dtx
+++ b/Master/texmf-dist/source/latex/l3kernel/l3sys.dtx
@@ -43,7 +43,7 @@
 %    }^^A
 % }
 %
-% \date{Released 2021-05-11}
+% \date{Released 2021-05-25}
 %
 % \maketitle
 %
@@ -121,6 +121,17 @@
 %   \tn{fmtname}).
 % \end{variable}
 %
+% \begin{function}[added = 2020-09-24, EXP]{\sys_timer:}
+%   \begin{syntax}
+%     \cs{sys_timer:}
+%   \end{syntax}
+%   Expands to the current value of the engine's timer clock, a
+%   non-negative integer.  This function is only defined for engines with
+%   timer support.  This command measures not just CPU time but
+%   real time (including time waiting for user input).  The unit are
+%   scaled seconds ($2^{-16}$ seconds).
+% \end{function}
+%
 % \section{Output format}
 %
 % \begin{function}[added = 2015-09-19, EXP, pTF]
@@ -863,6 +874,53 @@ end
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}[EXP]{\sys_timer:, \@@_elapsedtime:}
+% \begin{macro}[EXP, pTF]{\sys_if_timer_exist:}
+%   In \LuaTeX{}, create a pseudo-primitve, otherwise try to
+%   locate the real primitive.  The elapsed time will be
+%   available if this succeeds.
+%    \begin{macrocode}
+%</tex>
+%<*lua>
+  local gettimeofday = os.gettimeofday
+  local epoch = gettimeofday() - os.clock()
+  local write = tex.write
+  local tointeger = math.tointeger
+  luacmd('@@_elapsedtime:', function()
+    write(tointeger((gettimeofday() - epoch)*65536 // 1))
+  end, 'global')
+%</lua>
+%<*tex>
+\sys_if_engine_luatex:TF
+  {
+    \cs_new:Npn \sys_timer:
+      { \@@_elapsedtime: }
+  }
+  {
+    \cs_if_exist:NTF \tex_elapsedtime:D
+      {
+        \cs_new:Npn \sys_timer:
+          { \int_value:w \tex_elapsedtime:D }
+      }
+      {
+        \__kernel_msg_new:nnnn { kernel } { no-elapsed-time }
+          { No~clock~detected~for~#1. }
+          { The~current~engine~provides~no~way~to~access~the~system~time. }
+        \cs_new:Npn \sys_timer:
+          {
+            \int_value:w
+            \__kernel_msg_expandable_error:nnn { kernel } { no-elapsed-time }
+              { \sys_timer: }
+            \c_zero_int
+          }
+      }
+  }
+\@@_const:nn { sys_if_timer_exist }
+  { \cs_if_exist_p:N \tex_elapsedtime:D || \cs_if_exist_p:N \@@_elapsedtime: }
+%    \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
 % \subsubsection{Access to the shell}
 %
 % \begin{variable}{\c_sys_shell_escape_int}
-- 
cgit v1.2.3

