home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-28 | 27.2 KB | 1,048 lines |
- Newsgroups: comp.sources.unix
- From: panos@anchor.cs.colorado.edu (Panos Tsirigotis)
- Subject: v27i120: clc - C Libraries Collection, Part14/20
- References: <1.754527080.23891@gw.home.vix.com>
- Sender: unix-sources-moderator@gw.home.vix.com
- Approved: vixie@gw.home.vix.com
-
- Submitted-By: panos@anchor.cs.colorado.edu (Panos Tsirigotis)
- Posting-Number: Volume 27, Issue 120
- Archive-Name: clc/part14
-
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then unpack
- # it by saving it into a file and typing "sh file". To overwrite existing
- # files, type "sh file -c". You can also feed this as standard input via
- # unshar, or by typing "sh <file", e.g.. If this archive is complete, you
- # will see the following message at the end:
- # "End of archive 14 (of 20)."
- # Contents: INSTALL libs/src/sio/suite/print.c libs/src/timer/sysdep.c
- # Wrapped by panos@eclipse on Sun Nov 28 14:48:17 1993
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- if test -f 'INSTALL' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'INSTALL'\"
- else
- echo shar: Extracting \"'INSTALL'\" \(7979 characters\)
- sed "s/^X//" >'INSTALL' <<'END_OF_FILE'
- X---------------------------------------------------------------------------
- XNOTE: You may want to set your tabstop to 3; this will make everything
- X look properly indented.
- X---------------------------------------------------------------------------
- X
- X
- X1. Distribution
- X
- XThis library package is distributed in shar archive kit form. After all
- Xthe archives are unpacked, you should end up with the following
- Xdirectory structure:
- X
- X README : You should read this file first
- X INSTALL : This is this file
- X Makefile : Top-level makefile
- X libconf : Shell script for configuration support
- X fixman : Shell script for fixing man pages
- X sysinc : Shell script to create protected header files (you
- X may not need this)
- X ./libs
- X ./libs/include
- X ./libs/man
- X ./libs/lib
- X ./libs/src/{sio,str,pset,misc,xlog,timer,pq,fsma,dict}
- X
- X
- X
- X2. Requirements
- X
- XThe TIMER library requires a system that supports the setitimer(2)
- Xsystem call, and either the sigvec(2) or sigaction(2) system calls. If
- Xthese are not available on your system, this library will be useless.
- XThe rest of the libraries should work on any UNIX system.
- X
- X
- X3. Compiling
- X
- XYou can compile the libraries using the top level Makefile, or
- Xyou may go to each library directory and use the Makefile there.
- XIn the following I will assume the former approach.
- X
- X
- X3.1. Library dependencies
- X
- XSome of the libraries depend on others (i.e. they expect the header
- Xfiles exported by those libraries), so there are restrictions on
- Xthe order of compilation. The dependency list is as follows:
- X
- XSTR depends on SIO
- XTIMER depends on PQ
- XDICT depends on FSMA
- XXLOG depends on SIO
- X
- XThe only dependency you can work around is that of STR on SIO (in case
- Xyou want to use STR but not SIO). Check the README in libs/src/str
- Xfor more information. In the following, I will assume that SIO will
- Xalso be used.
- X
- XThe top level Makefile handles the compilation order correctly.
- X
- X
- X
- X3.2. Compiling using the top level Makefile
- X
- XThe majority of the libraries should compile without any problem. The
- Xonly possible exceptions are SIO, XLOG and TIMER because they depend on
- Xfacilities provided by the operating system. You can customize these
- Xlibraries for your system using appropriate preprocessor flags. These
- Xflags are documented in the makefiles of the particular libraries, as
- Xwell as on the top level Makefile.
- X
- XIf your system is running SunOS 4.x, Solaris 2.x, Ultrix 4.x, or if it
- Xis POSIX-compatible, you can find the appropriate flag settings in the
- Xtop level Makefile. If your system is not among those, you have two
- Xoptions: you can either check the top level Makefile for the particular
- Xflags that may need to be set, or you can use the libconf script whose
- Xpurpose is to determine the appropriate flags for your system.
- X
- Xlibconf relies on being able to interpret correctly the output of the
- X'nm' command. The distributed version of the script relies on BSD
- X4.3-style output. In this output, each symbol in an object file is
- Xpreceded by the letter 'T' if it is a function, or by the letter 'D' if
- Xit is a variable. The libconf script variables "nm_defined_func" and
- X"nm_defined_var" are set to these letters. If the output of 'nm' on
- Xyour system uses different conventions for determining what is a
- Xfunction and what is a variable, you should change the values of those
- Xtwo variables accordingly. Note that these values can be arbitrary
- Xregular expressions (which are parsed by egrep), not just single
- Xletters.
- X
- XFinally, the library man pages make use of the ".SB" request, which
- Xreduces the size of the following text by one point and makes it
- Xboldface. This is available on SunOS 4.x, but may not be available on
- Xyour system. If that is the case, you can use the fixman script to
- Xconvert all occurrences of ".SB" to ".B". The script is invoked with
- X fixman manpage manpage ...
- XIf the script modifies a manpage, it will also save the original in a
- Xfile named after the manpage, with the string ".orig" appended to its
- Xname. For example, if sio.3 is modified, then sio.3.orig will be the
- Xoriginal man page.
- X
- X
- X
- X3.3. Library creation and installation
- X
- XSince some libraries depend on others, the top level Makefile does not
- Xsimply compile each library, but also installs it. The installation
- Xprocess is controlled by the Makefile variables LIBDIR (the .a files
- Xwill go here), INCLUDEDIR (the include files will go here), and MANDIR
- X(the man pages will go here).
- X
- XBy default, the top level Makefile assumes that the 'ranlib' command
- Xneeds to be applied to each library archive. This is true for
- XBSD-derived systems, but is may be unnecessary for other systems (for
- Xexample, System V-derived systems). If this is the case for your
- Xsystem, you should set the RANLIB variable in the top level Makefile to
- X'true'.
- X
- XThe other possible installation complication is the 'install' command.
- XThe top level Makefile assumes a BSD 4.3-compatible install command
- Xthat accepts the "-c" option. If your system does not have such a
- Xcommand, use the following settings:
- X INSTALL = cp
- X FMODE =
- XIf your system has such a command but not at a standard place, set the
- XINSTALL variable to the pathname of the command (for example, for
- XSVR4-compatible systems, set INSTALL to "/usr/ucb/install -c".
- X
- XYou can undo an installation by typing "make uninstall". However, the
- Xvalues of the variables LIBDIR, INCLUDEDIR, and MANDIR should not have
- Xchanged since the last "make install".
- X
- X
- X
- X4. Compilation problems
- X
- X4.1. Unprotected system include files
- X
- XTypically, system include files start with the protective sequence
- X
- X#ifndef __special_flag
- X#define __special_flag
- X....
- X#endif
- X
- XThis allows the file to be included multiple times without a
- Xcompilation error. Some of the libraries rely on this property, so on
- Xsystems that don't have such include files, those libraries will fail
- Xto compile.
- X
- XTo circumvent this problem, I have provided the 'sysinc' script, which
- Xcan be used as follows:
- X
- X sysinc -d <clone_dir> header_files_and_C_files_of_all_libraries
- X
- XThe script will find all the system include files used by the specified
- Xheader and C-source files, and then it will create a "clone" directory
- Xstructure of include files with the same name as the system include
- Xfiles, under "clone_dir". These clone files will have the protective
- Xsequence, and will include the corresponding system include files.
- X
- XYou can then set the SYSINC variable of the top level Makefile as follows:
- X SYSINC = -I<clone_dir>
- XNote that "clone_dir" should be an absolute pathname.
- X
- X4.2. C compiler does not support 'void *' pointers
- X
- X libs/src/pset/pset.h: change the typedef of __pset_pointer from 'void *'
- X to 'char *'
- X libs/src/xlog/xlog.h: change the typedef of xlog_h from 'void *'
- X to 'char *'
- X libs/src/xlog/impl.h: in 'struct xlog' change the type of the
- X xl_callback_arg and xl_data fields from 'void *'
- X to 'char *'
- X libs/src/pq/pq.h: change the typedefs of pq_h and pq_obj from
- X 'void *' to 'char *'
- X libs/src/timer/timer.h: in 'struct timer_action' change the type of the
- X ta_arg field from 'void *' to 'char *';
- X also change the typedef of timer_h from 'void *'
- X to 'char *'
- X libs/src/timer/timer.c: in the line:
- X void *arg = tp->t_action.ta_arg ;
- X change the type of 'arg' from 'void *' to 'char *'
- X
- XYou may wonder why there is no '#ifdef' for this problem. The reason is
- Xthat decent C compilers have supported 'void *' pointers since a long time,
- Xand there is now a free C compiler, gcc, that also supports such pointers.
- XTherefore, I don't want to overburden the code with more '#ifdefs' just
- Xfor the sake of outdated C compilers.
- X
- X
- X5. Epilogue
- X
- XPlease send all comments/suggestions/bug-reports to panos@cs.colorado.edu
- X
- X -- Panos Tsirigotis, Nov. 26, 1993 --
- X
- END_OF_FILE
- if test 7979 -ne `wc -c <'INSTALL'`; then
- echo shar: \"'INSTALL'\" unpacked with wrong size!
- fi
- # end of 'INSTALL'
- fi
- if test -f 'libs/src/sio/suite/print.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/sio/suite/print.c'\"
- else
- echo shar: Extracting \"'libs/src/sio/suite/print.c'\" \(8243 characters\)
- sed "s/^X//" >'libs/src/sio/suite/print.c' <<'END_OF_FILE'
- X/*
- X * (c) Copyright 1992, 1993 by Panagiotis Tsirigotis
- X * All rights reserved. The file named COPYRIGHT specifies the terms
- X * and conditions for redistribution.
- X */
- X
- Xstatic char RCSid[] = "$Id: print.c,v 8.1 1993/03/13 01:21:48 panos Exp $" ;
- X
- X#include <stdio.h>
- X#include <math.h>
- X#include <values.h>
- X#include <string.h>
- X
- X#include "sio.h"
- X
- X#define FLUSH() fflush( stdout ) ; Sflush( 1 )
- X#define COMPARE( printf_count, sprint_count ) \
- X if ( printf_count != sprint_count ) \
- X printf( "printf_count = %d, sprint_count = %d\n", \
- X printf_count, sprint_count )
- X
- Xenum bool { NO = 0, YES = 1 } ;
- X
- Xenum test_flag
- X{
- X DECIMAL, HEX, CAP_HEX, OCTAL, UNSIGNED,
- X F_FLOAT, G_FLOAT, E_FLOAT, CAP_E_FLOAT, CAP_G_FLOAT,
- X CHAR, STRING,
- X POINTER,
- X BOUND,
- X N_FLAGS
- X} ;
- X
- Xtypedef enum test_flag FLAG ;
- X
- X#define CHECK( f ) if ( ! flags[ f ] ) return
- X
- X/*
- X * Flags
- X */
- Xenum bool flags[ N_FLAGS ] ;
- X
- Xchar *precision ;
- Xchar *width ;
- Xchar *print_flags ;
- X
- Xint i_begin = 123456 ;
- Xint i_end = 123470 ;
- Xint i_step = 1 ;
- X
- Xdouble f_begin = 1.234567654312 ;
- Xdouble f_end = 2.0 ;
- Xdouble f_step = 0.011 ;
- X
- X#define LEN( s ) ( s ? strlen( s ) : 0 )
- X
- Xchar *format( f )
- X char *f ;
- X{
- X char *malloc() ;
- X static char *newfmt ;
- X
- X if ( newfmt )
- X free( newfmt ) ;
- X
- X newfmt = malloc( strlen( f )
- X + LEN( precision ) + LEN( width ) + LEN( print_flags ) + 2 ) ;
- X (void) strcpy( newfmt, "%" ) ;
- X if ( print_flags )
- X (void) strcat( newfmt, print_flags ) ;
- X if ( width )
- X (void) strcat( newfmt, width ) ;
- X if ( precision )
- X (void) strcat( strcat( newfmt, "." ), precision ) ;
- X (void) strcat( newfmt, &f[1] ) ;
- X return( newfmt ) ;
- X}
- X
- X#define decimal_test() integer_test( "%d %d\n", DECIMAL )
- X#define hex_test() integer_test( "%x %x\n", HEX )
- X#define cap_hex_test() integer_test( "%X %X\n", CAP_HEX )
- X#define octal_test() integer_test( "%o %o\n", OCTAL )
- X#define unsigned_test() integer_test( "%u %u\n", UNSIGNED )
- X
- Xvoid integer_test( fmt, flag )
- X char *fmt ;
- X FLAG flag ;
- X{
- X int i ;
- X int ccs, ccp ;
- X
- X CHECK( flag ) ;
- X fmt = format( fmt ) ;
- X
- X for ( i = i_begin ; i < i_end ; i += i_step )
- X {
- X ccp = printf( fmt, -i, i ) ;
- X ccs = Sprint( 2, fmt, -i, i ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X }
- X}
- X
- X
- X#define f_float_test() fp_test( "%f\n", F_FLOAT )
- X#define g_float_test() fp_test( "%g\n", G_FLOAT )
- X#define e_float_test() fp_test( "%e\n", E_FLOAT )
- X#define cap_e_float_test() fp_test( "%E\n", CAP_E_FLOAT )
- X#define cap_g_float_test() fp_test( "%G\n", CAP_G_FLOAT )
- X
- Xvoid fp_test( fmt, flag )
- X char *fmt ;
- X FLAG flag ;
- X{
- X double d ;
- X double step ;
- X int ccs, ccp ;
- X
- X CHECK( flag ) ;
- X fmt = format( fmt ) ;
- X
- X for ( d = f_begin, step = f_step ; d < f_end ; d += step, step += step )
- X {
- X
- X ccp = printf( fmt, d ) ;
- X ccs = Sprint( 2, fmt, d ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X }
- X}
- X
- X
- Xvoid char_test()
- X{
- X char *s = "foobar" ;
- X int len = strlen( s ) ;
- X int i ;
- X char *fmt = "%c\n" ;
- X int ccs, ccp ;
- X
- X CHECK( CHAR ) ;
- X fmt = format( fmt ) ;
- X
- X for ( i = 0 ; i < len ; i++ )
- X {
- X ccp = printf( fmt, s[ i ] ) ;
- X ccs = Sprint( 2, fmt, s[ i ] ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X }
- X}
- X
- X
- Xvoid string_test()
- X{
- X static char *list[] =
- X {
- X "foobar",
- X "hello",
- X "world",
- X "this is a very long string, a really long string, really, true, honest",
- X "i am getting tired of this",
- X "SO THIS IS THE END",
- X 0
- X } ;
- X char *fmt = "%s\n" ;
- X char **p ;
- X int ccp, ccs ;
- X
- X CHECK( STRING ) ;
- X fmt = format( fmt ) ;
- X
- X for ( p = &list[ 0 ] ; *p ; p++ )
- X {
- X ccp = printf( fmt, *p ) ;
- X ccs = Sprint( 2, fmt, *p ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X }
- X}
- X
- X
- Xvoid pointer_test()
- X{
- X struct foo
- X {
- X char bar1 ;
- X short bar2 ;
- X int bar3 ;
- X long bar4 ;
- X char *bar5 ;
- X } foo, *end = &foo, *p ;
- X char *fmt = "%p\n" ;
- X int ccp, ccs ;
- X
- X CHECK( POINTER ) ;
- X fmt = format( fmt ) ;
- X
- X end += 10 ;
- X for ( p = &foo ; p < end ; p++ )
- X {
- X ccp = printf( fmt, p ) ;
- X ccs = Sprint( 2, fmt, p ) ;
- X FLUSH() ;
- X }
- X}
- X
- X
- X/*
- X * bound_test is only available on SunOS 4.x
- X */
- X#if defined( sun )
- X
- Xvoid bound_test()
- X{
- X char *fmt ;
- X double bound_values[ 10 ] ;
- X static char *bound_names[] =
- X {
- X "min_subnormal",
- X "max_subnormal",
- X "min_normal",
- X "max_normal",
- X "infinity",
- X "quiet_nan",
- X "signaling_nan"
- X } ;
- X int n_values ;
- X int i ;
- X int ccp, ccs ;
- X
- X bound_values[ 0 ] = min_subnormal() ;
- X bound_values[ 1 ] = max_subnormal() ;
- X bound_values[ 2 ] = min_normal() ;
- X bound_values[ 3 ] = max_normal() ;
- X bound_values[ 4 ] = infinity() ;
- X bound_values[ 5 ] = quiet_nan( 7L ) ;
- X bound_values[ 6 ] = signaling_nan( 7L ) ;
- X n_values = 7 ;
- X
- X CHECK( BOUND ) ;
- X
- X for ( i = 0 ; i < n_values ; i++ )
- X {
- X double d = bound_values[ i ] ;
- X char *name = bound_names[ i ] ;
- X
- X fmt = format( "%f (%s)\n" ) ;
- X ccp = printf( fmt, d, name ) ;
- X ccs = Sprint( 2, fmt, d, name ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X
- X fmt = format( "%e (%s)\n" ) ;
- X ccp = printf( fmt, d, name ) ;
- X ccs = Sprint( 2, fmt, d, name ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X
- X fmt = format( "%g (%s)\n" ) ;
- X ccp = printf( fmt, d, name ) ;
- X ccs = Sprint( 2, fmt, d, name ) ;
- X FLUSH() ;
- X COMPARE( ccp, ccs ) ;
- X }
- X
- X fmt = format( "%d (MININT)\n" ) ;
- X ccp = printf( fmt, -MAXINT-1 ) ;
- X ccs = Sprint( 2, fmt, -MAXINT-1 ) ;
- X COMPARE( ccp, ccs ) ;
- X}
- X#else
- Xvoid bound_test()
- X{
- X}
- X#endif
- X
- X
- Xint get_options( argc, argv )
- X int argc ;
- X char *argv[] ;
- X{
- X int arg_index = 1 ;
- X char *p ;
- X double atof() ;
- X
- X for ( arg_index = 1 ;
- X arg_index < argc && argv[ arg_index ][ 0 ] == '-' ; arg_index++ )
- X {
- X switch ( argv[ arg_index ][ 1 ] )
- X {
- X case 'd':
- X flags[ DECIMAL ] = YES ;
- X break ;
- X
- X case 'x':
- X flags[ HEX ] = YES ;
- X break ;
- X
- X case 'X':
- X flags[ CAP_HEX ] = YES ;
- X break ;
- X
- X case 'o':
- X flags[ OCTAL ] = YES ;
- X break ;
- X
- X case 'u':
- X flags[ UNSIGNED ] = YES ;
- X break ;
- X
- X case 'f':
- X flags[ F_FLOAT ] = YES ;
- X break ;
- X
- X case 'g':
- X flags[ G_FLOAT ] = YES ;
- X break ;
- X
- X case 'e':
- X flags[ E_FLOAT ] = YES ;
- X break ;
- X
- X case 'E':
- X flags[ CAP_E_FLOAT ] = YES ;
- X break ;
- X
- X case 'G':
- X flags[ CAP_G_FLOAT ] = YES ;
- X break ;
- X
- X case 'c':
- X flags[ CHAR ] = YES ;
- X break ;
- X
- X case 's':
- X flags[ STRING ] = YES ;
- X break ;
- X
- X case 'p':
- X flags[ POINTER ] = YES ;
- X break ;
- X
- X case 'b': /* this is for checking bounds in fp formats */
- X flags[ BOUND ] = YES ;
- X break ;
- X
- X case 'P': /* precision, must be followed by a number, e.g. -P10 */
- X precision = &argv[ arg_index ][ 2 ] ;
- X break ;
- X
- X case 'W': /* width, must be followed by a number, e.g. -w10 */
- X width = &argv[ arg_index ][ 2 ] ;
- X break ;
- X
- X case 'F': /* flags, whatever is after the F */
- X print_flags = &argv[ arg_index ][ 2 ] ;
- X break ;
- X
- X /*
- X * Options recognized in this case: -Vf, -Vi
- X * Usage: -V[if] start end step
- X */
- X case 'V':
- X /*
- X * Check if we have enough extra arguments
- X */
- X if ( argc - ( arg_index + 1 ) < 3 )
- X {
- X fprintf( stderr, "Insufficient # of args after V option\n" ) ;
- X exit( 1 ) ;
- X }
- X switch ( argv[ arg_index ][ 2 ] )
- X {
- X case 'f':
- X f_begin = atof( argv[ arg_index+1 ] ) ;
- X f_end = atof( argv[ arg_index+2 ] ) ;
- X f_step = atof( argv[ arg_index+3 ] ) ;
- X break ;
- X
- X case 'i':
- X i_begin = atoi( argv[ arg_index+1 ] ) ;
- X i_end = atoi( argv[ arg_index+2 ] ) ;
- X i_step = atoi( argv[ arg_index+3 ] ) ;
- X break ;
- X }
- X arg_index += 3 ;
- X break ;
- X
- X case 'S':
- X f_step = atof( &argv[ arg_index ][ 2 ] ) ;
- X break ;
- X }
- X }
- X return( arg_index ) ;
- X}
- X
- X
- X#define EQ( s1, s2 ) ( strcmp( s1, s2 ) == 0 )
- X
- X
- Xint main( argc, argv )
- X int argc ;
- X char *argv[] ;
- X{
- X
- X if ( Sbuftype( 2, SIO_LINEBUF ) == SIO_ERR )
- X {
- X char *msg = "Sbuftype failed\n" ;
- X
- X write( 2, msg, strlen( msg ) ) ;
- X exit( 1 ) ;
- X }
- X
- X if ( argc == 1 || argc == 2 && EQ( argv[ 1 ], "ALL" ) )
- X {
- X /* perform all tests */
- X int i ;
- X
- X for ( i = 0 ; i < N_FLAGS ; i++ )
- X flags[ i ] = YES ;
- X }
- X else
- X (void) get_options( argc, argv ) ;
- X
- X decimal_test() ;
- X hex_test() ;
- X cap_hex_test() ;
- X octal_test() ;
- X unsigned_test() ;
- X
- X f_float_test() ;
- X g_float_test() ;
- X e_float_test() ;
- X cap_g_float_test() ;
- X cap_e_float_test() ;
- X
- X string_test() ;
- X char_test() ;
- X pointer_test() ;
- X bound_test() ;
- X exit( 0 ) ;
- X}
- END_OF_FILE
- if test 8243 -ne `wc -c <'libs/src/sio/suite/print.c'`; then
- echo shar: \"'libs/src/sio/suite/print.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/sio/suite/print.c'
- fi
- if test -f 'libs/src/timer/sysdep.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'libs/src/timer/sysdep.c'\"
- else
- echo shar: Extracting \"'libs/src/timer/sysdep.c'\" \(7951 characters\)
- sed "s/^X//" >'libs/src/timer/sysdep.c' <<'END_OF_FILE'
- X/*
- X * (c) Copyright 1993 by Panagiotis Tsirigotis
- X * All rights reserved. The file named COPYRIGHT specifies the terms
- X * and conditions for redistribution.
- X */
- X
- X#include <signal.h>
- X#include <sys/time.h>
- X#include <sys/resource.h>
- X
- X#include "defs.h"
- X#include "impl.h"
- X#include "ostimer.h"
- X#include "timemacros.h"
- X
- X
- XPRIVATE void sigalrm_handler() ;
- XPRIVATE void sigvtalrm_handler() ;
- XPRIVATE void sigprof_handler() ;
- X
- XPRIVATE void get_real_time() ;
- XPRIVATE void get_virtual_time() ;
- XPRIVATE void get_prof_time() ;
- X
- X#define SIGNOSIG 0
- X
- X/*
- X * The reason for having the AVAILABLE/UNAVAILABLE fields instead of
- X * simply not having entries if a specified timer type is not supported,
- X * is that we use the timer type as an index into the os_timers[] array.
- X */
- Xstatic struct os_timer os_timers[] =
- X {
- X {
- X#if defined( ITIMER_REAL ) && ! defined( NO_ITIMER_REAL )
- X AVAILABLE, ITIMER_REAL, SIGALRM,
- X#else
- X UNAVAILABLE, 0, SIGNOSIG,
- X#endif
- X TIMER_REAL, sigalrm_handler, get_real_time },
- X
- X {
- X#if defined( ITIMER_VIRTUAL ) && ! defined( NO_ITIMER_VIRTUAL )
- X AVAILABLE, ITIMER_VIRTUAL, SIGVTALRM,
- X#else
- X UNAVAILABLE, 0, SIGNOSIG,
- X#endif
- X TIMER_VIRTUAL, sigvtalrm_handler, get_virtual_time },
- X
- X {
- X#if defined( ITIMER_PROF ) && ! defined( NO_ITIMER_PROF )
- X AVAILABLE, ITIMER_PROF, SIGPROF,
- X#else
- X UNAVAILABLE, 0, SIGNOSIG,
- X#endif
- X TIMER_PROF, sigprof_handler, get_prof_time },
- X
- X { UNAVAILABLE, 0, SIGNOSIG,
- X TIMER_REAL, NULL, NULL, }
- X } ;
- X
- X
- X/*
- X * The timer_block_mask blocks all timer signals when a timer signal
- X * happens (using the sa_mask field of struct sigaction). This is necessary
- X * when the user function associated with the timer does not return.
- X * Consider the following scenario:
- X * The user creates 2 timers, one TIMER_REAL (signal: SIGALRM), one
- X * TIMER_VIRTUAL (signal: SIGVTALRM).
- X * SIGALRM occurs first but before it is handled, SIGVTALRM happens.
- X * At this point both SIGARLM and SIGVTALRM are blocked.
- X * SIGVTALRM gets unblocked and the function for the TIMER_VIRTUAL is
- X * invoked and never returns. The function for the TIMER_REAL is never
- X * invoked (and any TIMER_REAL timers never expire).
- X */
- X#ifndef NO_POSIX_SIGS
- Xstatic sigset_t timer_block_mask ;
- X#else
- Xstatic int timer_block_mask ;
- X#endif
- X
- Xstatic int timer_block_mask_set ; /* flag */
- X
- X
- X/*
- X * Initialize the timer_block_mask.
- X * As a side-effect it also initializes the block_mask of each ostimer.
- X */
- XPRIVATE void set_timer_block_mask()
- X{
- X ostimer_s *otp ;
- X
- X#ifndef NO_POSIX_SIGS
- X (void) sigemptyset( &timer_block_mask ) ;
- X#else
- X /* timer_block_mask is a global variable so it is initialized to 0 */
- X#endif
- X
- X for ( otp = &os_timers[ 0 ] ; otp->ost_handler ; otp++ )
- X {
- X#ifndef NO_POSIX_SIGS
- X (void) sigemptyset( &otp->ost_block_mask ) ;
- X (void) sigaddset( &otp->ost_block_mask, otp->ost_signal ) ;
- X (void) sigaddset( &timer_block_mask, otp->ost_signal ) ;
- X#else
- X otp->ost_block_mask = sigmask( otp->ost_signal ) ;
- X timer_block_mask |= otp->ost_block_mask ;
- X#endif
- X }
- X
- X timer_block_mask_set = TRUE ;
- X}
- X
- X
- XPRIVATE ostimer_s *ostimer_find( type )
- X enum timer_types type ;
- X{
- X register ostimer_s *otp ;
- X
- X for ( otp = os_timers ; otp->ost_handler ; otp++ )
- X if ( otp->ost_timertype == type )
- X return( otp->ost_availability == AVAILABLE ? otp : OSTIMER_NULL ) ;
- X return( OSTIMER_NULL ) ;
- X}
- X
- X
- XPRIVATE int time_compare( p1, p2 )
- X pq_obj p1, p2 ;
- X{
- X return( TV_LT( TP( p1 )->t_expiration, TP( p2 )->t_expiration ) ) ;
- X}
- X
- X
- X/*
- X * Initialize an OS timer. The initialization steps are:
- X *
- X * create priority queue
- X * install signal handler
- X *
- X * We also initialize the timer_block_mask if it has not been initialized yet.
- X */
- Xostimer_s *__ostimer_init( tp, type )
- X timer_s *tp ;
- X enum timer_types type ;
- X{
- X#ifndef NO_POSIX_SIGS
- X struct sigaction sa ;
- X#else
- X struct sigvec sv ;
- X#endif
- X ostimer_s *otp ;
- X struct timer_q *tqp ;
- X
- X /*
- X * Find the corresponding ostimer
- X */
- X if ( ( otp = ostimer_find( type ) ) == OSTIMER_NULL )
- X HANDLE_ERROR( tp->t_flags, OSTIMER_NULL,
- X tp->t_errnop, TIMER_ENOTAVAILABLE,
- X "TIMER __ostimer_init: requested timer type not available\n" ) ;
- X
- X /*
- X * We use the value of ost_timerq to determine if the os_timer
- X * has been initialized.
- X */
- X tqp = &otp->ost_timerq ;
- X if ( tqp->tq_handle )
- X return( otp ) ;
- X
- X tqp->tq_handle = pq_create( time_compare,
- X tp->t_flags & TIMER_RETURN_ERROR ? PQ_RETURN_ERROR : PQ_NOFLAGS,
- X &tqp->tq_errno ) ;
- X if ( tqp->tq_handle == NULL )
- X {
- X *tp->t_errnop = TIMER_ENOMEM ;
- X return( OSTIMER_NULL ) ;
- X }
- X
- X if ( ! timer_block_mask_set )
- X set_timer_block_mask() ;
- X
- X#ifndef NO_POSIX_SIGS
- X sa.sa_handler = otp->ost_handler ;
- X sa.sa_mask = timer_block_mask ;
- X sa.sa_flags = 0 ;
- X if ( sigaction( otp->ost_signal, &sa, SIGACTION_NULL ) == -1 )
- X#else
- X sv.sv_handler = otp->ost_handler ;
- X sv.sv_mask = timer_block_mask ;
- X sv.sv_flags = 0 ;
- X if ( sigvec( otp->ost_signal, &sv, SIGVEC_NULL ) == -1 )
- X#endif
- X HANDLE_ERROR( tp->t_flags, OSTIMER_NULL, tp->t_errnop, TIMER_ESIGPROBLEM,
- X "TIMER __ostimer_init: signal handler installation failed\n" ) ;
- X return( otp ) ;
- X}
- X
- X
- X/*
- X * timer_* functions that need access to private data of ostimer
- X */
- Xvoid timer_block_type( type )
- X enum timer_types type ;
- X{
- X ostimer_s *otp = ostimer_find( type ) ;
- X
- X if ( otp == OSTIMER_NULL )
- X return ;
- X
- X#ifndef NO_POSIX_SIGS
- X (void) sigprocmask( SIG_BLOCK, &otp->ost_block_mask, SIGSET_NULL ) ;
- X#else
- X (void) sigblock( otp->ost_block_mask ) ;
- X#endif
- X}
- X
- X
- Xvoid timer_unblock_type( type )
- X enum timer_types type ;
- X{
- X ostimer_s *otp = ostimer_find( type ) ;
- X
- X if ( otp == OSTIMER_NULL )
- X return ;
- X
- X#ifndef NO_POSIX_SIGS
- X (void) sigprocmask( SIG_UNBLOCK, &otp->ost_block_mask, SIGSET_NULL ) ;
- X#else
- X {
- X int old_mask = sigblock( ~0 ) ;
- X
- X (void) sigsetmask( old_mask & ~otp->ost_block_mask ) ;
- X }
- X#endif
- X}
- X
- X
- Xvoid __ostimer_blockall()
- X{
- X#ifndef NO_POSIX_SIGS
- X (void) sigprocmask( SIG_BLOCK, &timer_block_mask, SIGSET_NULL ) ;
- X#else
- X (void) sigblock( timer_block_mask ) ;
- X#endif
- X}
- X
- X
- Xvoid __ostimer_unblockall()
- X{
- X#ifndef NO_POSIX_SIGS
- X (void) sigprocmask( SIG_UNBLOCK, &timer_block_mask, SIGSET_NULL ) ;
- X#else
- X int old_mask = sigblock( ~0 ) ;
- X
- X (void) sigsetmask( old_mask & ~timer_block_mask ) ;
- X#endif
- X}
- X
- X
- Xvoid __ostimer_unblockall_except( otp )
- X ostimer_s *otp ;
- X{
- X#ifndef NO_POSIX_SIGS
- X sigset_t new_mask = timer_block_mask ;
- X
- X (void) sigdelset( &new_mask, otp->ost_signal ) ;
- X (void) sigprocmask( SIG_UNBLOCK, &new_mask, SIGSET_NULL ) ;
- X#else
- X int old_mask = sigblock( ~0 ) ;
- X
- X (void) sigsetmask( ( old_mask & ~timer_block_mask )
- X | otp->ost_block_mask ) ;
- X#endif
- X}
- X
- X
- XPRIVATE void sigalrm_handler()
- X{
- X#ifdef DEBUG_MSGS
- X printf( "\tSIGALRM happened\n" ) ;
- X#endif
- X __ostimer_interrupt( &os_timers[ (int)TIMER_REAL ] ) ;
- X}
- X
- X
- XPRIVATE void sigvtalrm_handler()
- X{
- X#ifdef DEBUG_MSGS
- X printf( "\tSIGVTALRM happened\n" ) ;
- X#endif
- X __ostimer_interrupt( &os_timers[ (int)TIMER_VIRTUAL ] ) ;
- X}
- X
- X
- XPRIVATE void sigprof_handler()
- X{
- X#ifdef DEBUG_MSGS
- X printf( "\tSIGPROF happened\n" ) ;
- X#endif
- X __ostimer_interrupt( &os_timers[ (int)TIMER_PROF ] ) ;
- X}
- X
- X
- XPRIVATE void get_real_time( tvp )
- X struct timeval *tvp ;
- X{
- X#if defined( ITIMER_REAL ) && ! defined( NO_ITIMER_REAL )
- X (void) gettimeofday( tvp, TIMEZONE_NULL ) ;
- X#endif
- X}
- X
- X
- XPRIVATE void get_virtual_time( tvp )
- X struct timeval *tvp ;
- X{
- X#if defined( ITIMER_VIRTUAL ) && ! defined( NO_ITIMER_VIRTUAL )
- X struct rusage ru ;
- X
- X (void) getrusage( RUSAGE_SELF, &ru ) ;
- X *tvp = ru.ru_utime ;
- X#endif
- X}
- X
- X
- XPRIVATE void get_prof_time( tvp )
- X struct timeval *tvp ;
- X{
- X#if defined( ITIMER_PROF ) && ! defined( NO_ITIMER_PROF )
- X struct rusage ru ;
- X
- X (void) getrusage( RUSAGE_SELF, &ru ) ;
- X TV_ADD( *tvp, ru.ru_utime, ru.ru_stime ) ;
- X#endif
- X}
- X
- X
- END_OF_FILE
- if test 7951 -ne `wc -c <'libs/src/timer/sysdep.c'`; then
- echo shar: \"'libs/src/timer/sysdep.c'\" unpacked with wrong size!
- fi
- # end of 'libs/src/timer/sysdep.c'
- fi
- echo shar: End of archive 14 \(of 20\).
- cp /dev/null ark14isdone
- MISSING=""
- for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked all 20 archives.
- rm -f ark[1-9]isdone ark[1-9][0-9]isdone
- else
- echo You still need to unpack the following archives:
- echo " " ${MISSING}
- fi
- ## End of shell archive.
- exit 0
-