Back to index

glibc  2.9
msgportdemux.c
Go to the documentation of this file.
00001 /* Demux messages sent on the signal port.
00002    Copyright (C) 1991,92,94,95,97,99 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <hurd.h>
00021 #include <hurd/signal.h>
00022 #include <stddef.h>
00023 
00024 struct demux
00025   {
00026     struct demux *next;
00027     boolean_t (*demux) (mach_msg_header_t *inp,
00028                      mach_msg_header_t *outp);
00029   };
00030 
00031 struct demux *_hurd_msgport_demuxers = NULL;
00032 
00033 extern boolean_t __msg_server (mach_msg_header_t *inp,
00034                             mach_msg_header_t *outp);
00035 
00036 static boolean_t
00037 msgport_server (mach_msg_header_t *inp,
00038               mach_msg_header_t *outp)
00039 {
00040   extern boolean_t _S_msg_server (mach_msg_header_t *inp,
00041                               mach_msg_header_t *outp);
00042   extern boolean_t _S_exc_server (mach_msg_header_t *inp,
00043                               mach_msg_header_t *outp);
00044   struct demux *d;
00045 
00046   for (d = _hurd_msgport_demuxers; d != NULL; d = d->next)
00047     if ((*d->demux) (inp, outp))
00048       return 1;
00049 
00050   return (_S_exc_server (inp, outp) ||
00051          _S_msg_server (inp, outp));
00052 }
00053 
00054 /* This is the code that the signal thread runs.  */
00055 void
00056 _hurd_msgport_receive (void)
00057 {
00058   /* Get our own sigstate cached so we never again have to take a lock to
00059      fetch it.  There is much code in hurdsig.c that operates with some
00060      sigstate lock held, which will deadlock with _hurd_thread_sigstate.
00061 
00062      Furthermore, in the cthreads case this is the convenient spot
00063      to initialize _hurd_msgport_thread (see hurdsig.c:_hurdsig_init).  */
00064 
00065   _hurd_msgport_thread = _hurd_self_sigstate ()->thread;
00066 
00067   while (1)
00068     (void) __mach_msg_server (msgport_server, __vm_page_size, _hurd_msgport);
00069 }