Win32 signal code - first try

From: "Magnus Hagander" <mha(at)sollentuna(dot)net>
To: <pgsql-patches(at)postgresql(dot)org>
Cc: "pgsql-hackers-win32" <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: Win32 signal code - first try
Date: 2004-01-08 20:27:24
Message-ID: 6BCB9D8A16AC4241919521715F4D8BCE2A6A5E@algol.sollentuna.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers-win32 pgsql-patches

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

Attachment Content-Type Size
pgsignal_w32.h application/octet-stream 2.6 KB
pgsignal_w32.c application/octet-stream 5.8 KB
pgsignal_srvtest.c application/octet-stream 480 bytes
pgkill.c application/octet-stream 469 bytes

Browse pgsql-hackers-win32 by date

  From Date Subject
Next Message Merlin Moncure 2004-01-08 21:08:19 Re: Win32 signal code - first try
Previous Message Andrew Dunstan 2004-01-08 19:50:46 Re: Signals on Win32 (yet again)

Browse pgsql-patches by date

  From Date Subject
Next Message Bruce Momjian 2004-01-08 20:44:24 Re: psql \i handling ~ in specified file name
Previous Message Jan Wieck 2004-01-08 19:26:09 Re: fork/exec patch: pre-CreateProcess finalization