User timeouts for scheduling functions - Mailing list pgsql-hackers

From Steve Senior
Subject User timeouts for scheduling functions
Date
Msg-id B0344A8C-9D4A-4838-B362-52BCB1CFE928@googlemail.com
Whole thread Raw
List pgsql-hackers
I'm prototyping an extension in which I need to execute a C function repeatedly on a timer as part of a sql execution hook, and end it when I choose.

I've spent the time reading these lists, the documentation etc and the only solution I saw that wouldn't require a patch was user-definable timeouts https://github.com/postgres/postgres/blob/master/src/include/utils/timeout.h#L40.

I have a working implementation that at a high level does the following

/* register and enable the timeout to call my_handler_proc every second */
tId = RegisterTimeout(USER_TIMEOUT, my_handler_proc);
enable_timeout_after((int)tId, 1000);

...

/* stop the timeout */
disable_timeout((int)tId, 0);

Note: I'm also working on the code to ensure I don't try to allocate beyond MAX_TIMEOUTS but I haven't shown that here for brevity.

My question really is: should I be doing this? Is it safe? I can't find this documented nor any other examples of code that uses this which is a red flag for me. 

Thanks in advance,
Steve.

pgsql-hackers by date:

Previous
From: Arseniy Mukhin
Date:
Subject: Re: Amcheck verification of GiST and GIN
Next
From: Потапов Александр
Date:
Subject: Re: Init connection time grows quadratically