On 4 Nov. 2016 06:05, "Clifford Hammerschmidt" <tanglebo...@gmail.com> wrote: > > Hi all, > > Apologies in advance if this isn't the right place to be posting this. > > I've started work on a plugin in C (https://github.com/tanglebones/pg_tuid) for generating generally monotonically ascending UUIDs (aka TUIDs), and after googling around I couldn't find any guidence on a few things. (It's hard to google for anything in the postgres C api as most results coming back are for using postgres itself, not developing plugins for postgres.) > > I'm looking for the idiomatic (and portable) way of: > > 1) getting microseconds (or nanoseconds) from UTC epoch in a plugin
GetCurrentIntegerTimestamp() > 2) getting an exclusive lock for a user plugin to serialize access to its shared state (I'm assuming that plugins must be reentrant) Allocate an LWLock in your shared memory segment and use it to arbitrate access. Multiple examples in contrib. Lwlock allocation infonin developer docs. > 3) creating a configuration variable for a plugin and accessing its values in the plugin. (e.g. `set plugin.configuration_variable=1` or somesuch) DefineCustomIntegerVariable etc (I think, name not exactly right? On phone). See guc.h .