all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Function to make a struct timespec from a floating point number?
       [not found] <87czkm1sry.fsf.ref@yahoo.com>
@ 2022-01-20 12:44 ` Po Lu
  2022-01-20 17:45   ` Eli Zaretskii
                     ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Po Lu @ 2022-01-20 12:44 UTC (permalink / raw)
  To: emacs-devel

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.

Thanks.



^ 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-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 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 17:45   ` Eli Zaretskii
@ 2022-01-21  0:51     ` Po Lu
  0 siblings, 0 replies; 8+ messages in thread
From: Po Lu @ 2022-01-21  0:51 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Is dtotimespec what you want?  It's a Gnulib function, we use it in
> process.c.

It's precisely what I was looking for, thanks!



^ 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

* 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

end of thread, other threads:[~2022-01-21  5:46 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <87czkm1sry.fsf.ref@yahoo.com>
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-21  1:37     ` Po Lu
2022-01-21  5:46       ` tomas
2022-01-20 18:31   ` Robin Tarsiger
2022-01-21  1:36     ` Po Lu

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.