From a2a67cd520b9841114d69a87a423dabcb3b4368e Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Sun, 2 Aug 2009 21:32:04 +0000 Subject: RTS tidyup sweep, first phase The first phase of this tidyup is focussed on the header files, and in particular making sure we are exposinng publicly exactly what we need to, and no more. - Rts.h now includes everything that the RTS exposes publicly, rather than a random subset of it. - Most of the public header files have moved into subdirectories, and many of them have been renamed. But clients should not need to include any of the other headers directly, just #include the main public headers: Rts.h, HsFFI.h, RtsAPI.h. - All the headers needed for via-C compilation have moved into the stg subdirectory, which is self-contained. Most of the headers for the rest of the RTS APIs have moved into the rts subdirectory. - I left MachDeps.h where it is, because it is so widely used in Haskell code. - I left a deprecated stub for RtsFlags.h in place. The flag structures are now exposed by Rts.h. - Various internal APIs are no longer exposed by public header files. - Various bits of dead code and declarations have been removed - More gcc warnings are turned on, and the RTS code is more warning-clean. - More source files #include "PosixSource.h", and hence only use standard POSIX (1003.1c-1995) interfaces. There is a lot more tidying up still to do, this is just the first pass. I also intend to standardise the names for external RTS APIs (e.g use the rts_ prefix consistently), and declare the internal APIs as hidden for shared libraries. --- rts/posix/FileLock.c | 5 ++-- rts/posix/FileLock.h | 15 ++++++++++++ rts/posix/Itimer.c | 35 ++++----------------------- rts/posix/Itimer.h | 5 ---- rts/posix/OSMem.c | 10 ++++---- rts/posix/OSThreads.c | 3 ++- rts/posix/Select.c | 13 ++++------- rts/posix/Select.h | 17 ++++---------- rts/posix/Signals.c | 11 ++++----- rts/posix/TTY.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ rts/posix/TTY.h | 15 ++++++++++++ 11 files changed, 123 insertions(+), 71 deletions(-) create mode 100644 rts/posix/FileLock.h create mode 100644 rts/posix/TTY.c create mode 100644 rts/posix/TTY.h (limited to 'rts/posix') diff --git a/rts/posix/FileLock.c b/rts/posix/FileLock.c index 26e9de4dc2..a6052c7381 100644 --- a/rts/posix/FileLock.c +++ b/rts/posix/FileLock.c @@ -6,11 +6,12 @@ * * ---------------------------------------------------------------------------*/ +#include "PosixSource.h" #include "Rts.h" -#include "Hash.h" + #include "FileLock.h" +#include "Hash.h" #include "RtsUtils.h" -#include "OSThreads.h" #include #include diff --git a/rts/posix/FileLock.h b/rts/posix/FileLock.h new file mode 100644 index 0000000000..2edee5ba6e --- /dev/null +++ b/rts/posix/FileLock.h @@ -0,0 +1,15 @@ +/* ----------------------------------------------------------------------------- + * + * (c) The GHC Team, 2007 + * + * File locking support as required by Haskell 98 + * + * ---------------------------------------------------------------------------*/ + +#ifndef POSIX_FILELOCK_H +#define POSIX_FILELOCK_H + +void initFileLocking(void); +void freeFileLocking(void); + +#endif /* POSIX_FILELOCK_H */ diff --git a/rts/posix/Itimer.c b/rts/posix/Itimer.c index eb26cd3699..3a09e804b5 100644 --- a/rts/posix/Itimer.c +++ b/rts/posix/Itimer.c @@ -16,15 +16,15 @@ * Hence, we use the old-fashioned @setitimer@ that just about everyone seems * to support. So much for standards. */ + +#include "PosixSource.h" #include "Rts.h" -#include "RtsFlags.h" -#include "Timer.h" + #include "Ticker.h" -#include "posix/Itimer.h" +#include "Itimer.h" #include "Proftimer.h" -#include "Storage.h" #include "Schedule.h" -#include "posix/Select.h" +#include "Select.h" /* As recommended in the autoconf manual */ # ifdef TIME_WITH_SYS_TIME @@ -229,31 +229,6 @@ exitTicker(void) #endif } -#if 0 -/* Currently unused */ -void -block_vtalrm_signal(void) -{ - sigset_t signals; - - sigemptyset(&signals); - sigaddset(&signals, ITIMER_SIGNAL); - - (void) sigprocmask(SIG_BLOCK, &signals, NULL); -} - -void -unblock_vtalrm_signal(void) -{ - sigset_t signals; - - sigemptyset(&signals); - sigaddset(&signals, ITIMER_SIGNAL); - - (void) sigprocmask(SIG_UNBLOCK, &signals, NULL); -} -#endif - /* gettimeofday() takes around 1us on our 500MHz PIII. Since we're * only calling it 50 times/s, it shouldn't have any great impact. */ diff --git a/rts/posix/Itimer.h b/rts/posix/Itimer.h index 09d01bde54..4cae935710 100644 --- a/rts/posix/Itimer.h +++ b/rts/posix/Itimer.h @@ -10,10 +10,5 @@ #define ITIMER_H extern lnat getourtimeofday ( void ); -#if 0 -/* unused */ -extern void block_vtalrm_signal ( void ); -extern void unblock_vtalrm_signal ( void ); -#endif #endif /* ITIMER_H */ diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c index 51737ad650..0a37256022 100644 --- a/rts/posix/OSMem.c +++ b/rts/posix/OSMem.c @@ -6,12 +6,12 @@ * * ---------------------------------------------------------------------------*/ -/* This is non-posix compliant. */ -/* #include "PosixSource.h" */ +// This is non-posix compliant. +// #include "PosixSource.h" #include "Rts.h" -#include "OSMem.h" -#include "RtsFlags.h" + +#include "sm/OSMem.h" #ifdef HAVE_UNISTD_H #include @@ -138,7 +138,7 @@ static void * gen_map_mblocks (lnat size) { int slop; - void *ret; + StgWord8 *ret; // Try to map a larger block, and take the aligned portion from // it (unmap the rest). diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c index 324701d40d..a813eebf9e 100644 --- a/rts/posix/OSThreads.c +++ b/rts/posix/OSThreads.c @@ -13,9 +13,10 @@ #define _GNU_SOURCE #endif +#include "PosixSource.h" #include "Rts.h" + #if defined(THREADED_RTS) -#include "OSThreads.h" #include "RtsUtils.h" #include "Task.h" diff --git a/rts/posix/Select.c b/rts/posix/Select.c index 32dca96cd8..46db4054bb 100644 --- a/rts/posix/Select.c +++ b/rts/posix/Select.c @@ -6,19 +6,16 @@ * * ---------------------------------------------------------------------------*/ -/* we're outside the realms of POSIX here... */ -/* #include "PosixSource.h" */ - +#include "PosixSource.h" #include "Rts.h" -#include "Storage.h" + +#include "Signals.h" #include "Schedule.h" #include "RtsUtils.h" -#include "RtsFlags.h" -#include "Timer.h" #include "Itimer.h" -#include "Signals.h" #include "Capability.h" -#include "posix/Select.h" +#include "Select.h" +#include "AwaitEvent.h" # ifdef HAVE_SYS_TYPES_H # include diff --git a/rts/posix/Select.h b/rts/posix/Select.h index 8825562974..e92a4bc889 100644 --- a/rts/posix/Select.h +++ b/rts/posix/Select.h @@ -6,21 +6,12 @@ * * -------------------------------------------------------------------------*/ -#ifndef SELECT_H -#define SELECT_H +#ifndef POSIX_SELECT_H +#define POSIX_SELECT_H #if !defined(THREADED_RTS) /* In Select.c */ -extern lnat RTS_VAR(timestamp); - -/* awaitEvent(rtsBool wait) - * - * Checks for blocked threads that need to be woken. - * - * Called from STG : NO - * Locks assumed : sched_mutex - */ -void awaitEvent(rtsBool wait); /* In Select.c */ +extern lnat timestamp; #endif -#endif /* SELECT_H */ +#endif /* POSIX_SELECT_H */ diff --git a/rts/posix/Signals.c b/rts/posix/Signals.c index ace58c2f98..660065734b 100644 --- a/rts/posix/Signals.c +++ b/rts/posix/Signals.c @@ -6,18 +6,15 @@ * * ---------------------------------------------------------------------------*/ -/* This is non-Posix-compliant. - #include "PosixSource.h" -*/ +#include "PosixSource.h" #include "Rts.h" -#include "SchedAPI.h" + #include "Schedule.h" #include "RtsSignals.h" -#include "posix/Signals.h" +#include "Signals.h" #include "RtsUtils.h" -#include "RtsFlags.h" #include "Prelude.h" -#include "ThrIOManager.h" +#include "Stable.h" #ifdef alpha_HOST_ARCH # if defined(linux_HOST_OS) diff --git a/rts/posix/TTY.c b/rts/posix/TTY.c new file mode 100644 index 0000000000..d39ef37b86 --- /dev/null +++ b/rts/posix/TTY.c @@ -0,0 +1,65 @@ +/* ----------------------------------------------------------------------------- + * + * (c) The GHC Team, 1998-2009 + * + * TTY-related functionality + * + * ---------------------------------------------------------------------------*/ + +#include "PosixSource.h" +#include "Rts.h" + +#include "RtsUtils.h" // __hscore_get/set prototypes +#include "TTY.h" + +#ifdef HAVE_TERMIOS_H +#include +#endif +#ifdef HAVE_SIGNAL_H +#include +#endif + +// Here we save the terminal settings on the standard file +// descriptors, if we need to change them (eg. to support NoBuffering +// input). +static void *saved_termios[3] = {NULL,NULL,NULL}; + +void* +__hscore_get_saved_termios(int fd) +{ + return (0 <= fd && fd < (int)(sizeof(saved_termios) / sizeof(*saved_termios))) ? + saved_termios[fd] : NULL; +} + +void +__hscore_set_saved_termios(int fd, void* ts) +{ + if (0 <= fd && fd < (int)(sizeof(saved_termios) / sizeof(*saved_termios))) { + saved_termios[fd] = ts; + } +} + +void +resetTerminalSettings (void) +{ +#if HAVE_TERMIOS_H + // Reset the terminal settings on the standard file descriptors, + // if we changed them. See System.Posix.Internals.tcSetAttr for + // more details, including the reason we termporarily disable + // SIGTTOU here. + { + int fd; + sigset_t sigset, old_sigset; + sigemptyset(&sigset); + sigaddset(&sigset, SIGTTOU); + sigprocmask(SIG_BLOCK, &sigset, &old_sigset); + for (fd = 0; fd <= 2; fd++) { + struct termios* ts = (struct termios*)__hscore_get_saved_termios(fd); + if (ts != NULL) { + tcsetattr(fd,TCSANOW,ts); + } + } + sigprocmask(SIG_SETMASK, &old_sigset, NULL); + } +#endif +} diff --git a/rts/posix/TTY.h b/rts/posix/TTY.h new file mode 100644 index 0000000000..f291d30de4 --- /dev/null +++ b/rts/posix/TTY.h @@ -0,0 +1,15 @@ +/* ----------------------------------------------------------------------------- + * + * (c) The GHC Team, 1998-2009 + * + * TTY-related functionality + * + * ---------------------------------------------------------------------------*/ + +#ifndef POSIX_TTY_H +#define POSIX_TTY_H + +void resetTerminalSettings (void); + +#endif /* POSIX_TTY_H */ + -- cgit v1.2.1