Win32 signal code - first try

Started by Magnus Haganderover 22 years ago2 messagespatches
Jump to latest
#1Magnus Hagander
magnus@hagander.net

Hi!

Here is a first sketch at Win32 signal handling. First a couple of
comments:

* This is just two files. It is not integrated with postgresql yet.

* Uses named pipes. Shared mem was slightly faster, named pipes a lot
cleaner. And the signal handlers themselves should not be performance
critical, AFAICS.

* Does *not* use user APCs. Why? Well, we had to use polling. And with
user APCs we'd have to go into kernel mode (however briefly) on every
poll. I replaced that with a simple counter that is checked. Thast way
we don't slow down the main path of the program much.

* It is then checked again while protected with a critical section, to
make sure we don't setp on our own toes from two threads.

* A user APC is queued on every signal anyway. This is only to break out
of SleepEx/WaitForMultipleObjectsEx etc functions. Normally, we pick the
signals up with polling.

A couple of questions that need answering:

* Where to put the polling. We need to find a reasonable limited number
of places. They just need PG_POLL_SIGNALS() there to go. Also, do we
want this one #ifdef:ed in every place, or just #define it to nothing at
all on non-windows platforms?

* Where to put the functions. Right now, it's just a separate file. Do
we want to keep it in separate files, or put it in existing files with
#ifdef:s? Or combination?

* Function names - I haven't looked at naming conventions at all :-)

* We need to replace any blocking waits (such as select() and sleep())
with "Ex functions" if we want signals to fire while waiting.

Probably a bunch more things I forgot to write right now.

Oh, and I've included two very small testfiles - "pgsignal_srvtest.c"
which is a sample server and "pgkill.c" which is a sample client. Very
ugly code, but it should show how it's intended to be used :-)

Anyway. Comments on these points in particular, and in the whole thing
in general? Workable path?

//Magnus

Attachments:

pgsignal_w32.happlication/octet-stream; name=pgsignal_w32.hDownload
pgsignal_w32.capplication/octet-stream; name=pgsignal_w32.cDownload
pgsignal_srvtest.capplication/octet-stream; name=pgsignal_srvtest.cDownload
pgkill.capplication/octet-stream; name=pgkill.cDownload
#2Claudio Natoli
claudio.natoli@memetrics.com
In reply to: Magnus Hagander (#1)
Re: Win32 signal code - first try

Also, do we want this one #ifdef:ed in every place, or just
#define it to nothing at all on non-windows platforms?

I imagine the latter will be cleaner.

Anyway. Comments on these points in particular, and in the whole thing in

general? Workable path?

I think it looks great. Well done!

Cheers,
Claudio
--- 
Certain disclaimers and policies apply to all email sent from Memetrics.
For the full text of these disclaimers and policies see 
<a
href="http://www.memetrics.com/emailpolicy.html">http://www.memetrics.com/em
ailpolicy.html</a>