Back to index

glibc  2.9
set-hooks.h
Go to the documentation of this file.
00001 /* Macros for using symbol sets for running lists of functions.
00002    Copyright (C) 1994, 1995, 1997, 2000, 2003 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 #ifndef _SET_HOOKS_H
00021 #define _SET_HOOKS_H 1
00022 
00023 #define __need_size_t
00024 #include <stddef.h>
00025 #include <sys/cdefs.h>
00026 
00027 #ifdef symbol_set_define
00028 /* Define a hook variable called NAME.  Functions put on this hook take
00029    arguments described by PROTO.  Use `text_set_element (NAME, FUNCTION)'
00030    from gnu-stabs.h to add a function to the hook.  */
00031 
00032 # define DEFINE_HOOK(NAME, PROTO)         \
00033   typedef void __##NAME##_hook_function_t PROTO; \
00034   symbol_set_define (NAME)
00035 
00036 # define DECLARE_HOOK(NAME, PROTO)        \
00037   typedef void __##NAME##_hook_function_t PROTO;\
00038   symbol_set_declare (NAME)
00039 
00040 /* Run all the functions hooked on the set called NAME.
00041    Each function is called like this: `function ARGS'.  */
00042 
00043 # define RUN_HOOK(NAME, ARGS)                                               \
00044 do {                                                                 \
00045   void *const *__unbounded ptr;                                             \
00046   for (ptr = (void *const *) symbol_set_first_element (NAME);               \
00047        ! symbol_set_end_p (NAME, ptr); ++ptr)                               \
00048     (*(__##NAME##_hook_function_t *) *ptr) ARGS;                     \
00049 } while (0)
00050 
00051 /* Define a hook variable with NAME and PROTO, and a function called RUNNER
00052    which calls each function on the hook in turn, with ARGS.  */
00053 
00054 # define DEFINE_HOOK_RUNNER(name, runner, proto, args) \
00055 DEFINE_HOOK (name, proto); \
00056 extern void runner proto; void runner proto { RUN_HOOK (name, args); }
00057 
00058 #else
00059 
00060 /* The system does not provide necessary support for this.  */
00061 # define DEFINE_HOOK(NAME, PROTO)
00062 
00063 # define DECLARE_HOOK(NAME, PROTO)
00064 
00065 # define RUN_HOOK(NAME, ARGS)
00066 
00067 # define DEFINE_HOOK_RUNNER(name, runner, proto, args)
00068 
00069 #endif
00070 
00071 #endif /* set-hooks.h */