* Re: Function to make a struct timespec from a floating point number?
2022-01-20 12:44 ` Function to make a struct timespec from a floating point number? Po Lu
@ 2022-01-20 17:45 ` Eli Zaretskii
2022-01-21 0:51 ` Po Lu
2022-01-20 18:21 ` tomas
2022-01-20 18:31 ` Robin Tarsiger
2 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2022-01-20 17:45 UTC (permalink / raw)
To: Po Lu; +Cc: emacs-devel
> From: Po Lu <luangruo@yahoo.com>
> Date: Thu, 20 Jan 2022 20:44:01 +0800
>
> I recall there being a function in the Emacs sources to construct a
> `struct timespec' from a floating point number denoting seconds.
>
> I would like to use it to allow setting `polling-period' to a period
> less than one second, so that C-g can be detected faster in the NS port.
>
> Does anyone remember the name of that function, if it does exist? I
> don't want to reinvent the wheel.
Is dtotimespec what you want? It's a Gnulib function, we use it in
process.c.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Function to make a struct timespec from a floating point number?
2022-01-20 12:44 ` Function to make a struct timespec from a floating point number? Po Lu
2022-01-20 17:45 ` Eli Zaretskii
@ 2022-01-20 18:21 ` tomas
2022-01-21 1:37 ` Po Lu
2022-01-20 18:31 ` Robin Tarsiger
2 siblings, 1 reply; 8+ messages in thread
From: tomas @ 2022-01-20 18:21 UTC (permalink / raw)
To: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 844 bytes --]
On Thu, Jan 20, 2022 at 08:44:01PM +0800, Po Lu wrote:
> I recall there being a function in the Emacs sources to construct a
> `struct timespec' from a floating point number denoting seconds.
That might be `time-convert':
(let* ((tim0 (current-time))
(ftim (float-time tim0))
(tim1 (time-convert ftim)))
(message "tim0: %S ftim: %S tim1: %S\n" tim0 ftim tim1))
=> tim0: (25065 42935 269749 160000) ftim: 1642702775.2697492 tim1: (25065 42935 269749 164581)
(some stuff in the lower bits seems to get lost in translation, alas :)
> I would like to use it to allow setting `polling-period' to a period
> less than one second, so that C-g can be detected faster in the NS port.
>
> Does anyone remember the name of that function, if it does exist? I
> don't want to reinvent the wheel.
HTH
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Function to make a struct timespec from a floating point number?
2022-01-20 18:21 ` tomas
@ 2022-01-21 1:37 ` Po Lu
2022-01-21 5:46 ` tomas
0 siblings, 1 reply; 8+ messages in thread
From: Po Lu @ 2022-01-21 1:37 UTC (permalink / raw)
To: tomas; +Cc: emacs-devel
<tomas@tuxteam.de> writes:
> That might be `time-convert':
>
> (let* ((tim0 (current-time))
> (ftim (float-time tim0))
> (tim1 (time-convert ftim)))
> (message "tim0: %S ftim: %S tim1: %S\n" tim0 ftim tim1))
>
> => tim0: (25065 42935 269749 160000) ftim: 1642702775.2697492 tim1: (25065 42935 269749 164581)
>
> (some stuff in the lower bits seems to get lost in translation, alas :)
Thanks, but that wasn't what I was looking for, since it deals with Lisp
timestamps and not `struct timespec's on the C level.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Function to make a struct timespec from a floating point number?
2022-01-21 1:37 ` Po Lu
@ 2022-01-21 5:46 ` tomas
0 siblings, 0 replies; 8+ messages in thread
From: tomas @ 2022-01-21 5:46 UTC (permalink / raw)
To: Po Lu; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 373 bytes --]
On Fri, Jan 21, 2022 at 09:37:25AM +0800, Po Lu wrote:
> <tomas@tuxteam.de> writes:
>
> > That might be `time-convert':
[...]
> Thanks, but that wasn't what I was looking for, since it deals with Lisp
> timestamps and not `struct timespec's on the C level.
Oh, sorry. I mis-parsed the "srtuct timespec" part, although it was
clear enough.
Cheers
--
t
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Function to make a struct timespec from a floating point number?
2022-01-20 12:44 ` Function to make a struct timespec from a floating point number? Po Lu
2022-01-20 17:45 ` Eli Zaretskii
2022-01-20 18:21 ` tomas
@ 2022-01-20 18:31 ` Robin Tarsiger
2022-01-21 1:36 ` Po Lu
2 siblings, 1 reply; 8+ messages in thread
From: Robin Tarsiger @ 2022-01-20 18:31 UTC (permalink / raw)
To: luangruo; +Cc: emacs-devel
Po Lu wrote:
> I recall there being a function in the Emacs sources to construct a
> `struct timespec' from a floating point number denoting seconds.
>
> I would like to use it to allow setting `polling-period' to a period
> less than one second, so that C-g can be detected faster in the NS port.
>
> Does anyone remember the name of that function, if it does exist? I
> don't want to reinvent the wheel.
I spy a ‘dtotimespec’ in lib/dtotimespec.c. Is that what you wanted?
> Thanks.
In case it's useful to you in the future, I obtained that by a fairly
simple search across the C files for the expected return type at bol.
I used ‘less’ at the command line, but ‘dired-do-find-regexp’ would
have offered something similar. There are not many functions nor global
variables with a ‘struct timespec’ type.
-RTT
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Function to make a struct timespec from a floating point number?
2022-01-20 18:31 ` Robin Tarsiger
@ 2022-01-21 1:36 ` Po Lu
0 siblings, 0 replies; 8+ messages in thread
From: Po Lu @ 2022-01-21 1:36 UTC (permalink / raw)
To: Robin Tarsiger; +Cc: emacs-devel
Robin Tarsiger <rtt@dasyatidae.com> writes:
> I spy a ‘dtotimespec’ in lib/dtotimespec.c. Is that what you wanted?
>
>> Thanks.
>
> In case it's useful to you in the future, I obtained that by a fairly
> simple search across the C files for the expected return type at bol.
> I used ‘less’ at the command line, but ‘dired-do-find-regexp’ would
> have offered something similar. There are not many functions nor global
> variables with a ‘struct timespec’ type.
Thanks. dtotimespec is indeed what I wanted.
^ permalink raw reply [flat|nested] 8+ messages in thread