summaryrefslogtreecommitdiff
path: root/rts/posix
diff options
context:
space:
mode:
authorGabor Greif <ggreif@gmail.com>2014-08-08 18:01:19 +0200
committerGabor Greif <ggreif@gmail.com>2014-08-08 18:01:19 +0200
commit5f003d228340c3ce8e500f9053f353c58dc1dc94 (patch)
treea855b0f173ff635b48354e1136ef6cbb2a1214a4 /rts/posix
parentff9c5570395bcacf8963149b3a8475f5644ce694 (diff)
parentdff0623d5ab13222c06b3ff6b32793e05b417970 (diff)
downloadhaskell-wip/generics-propeq.tar.gz
Merge branch 'master' into wip/generics-propeqwip/generics-propeq
Conflicts: compiler/typecheck/TcGenGenerics.lhs
Diffstat (limited to 'rts/posix')
-rw-r--r--rts/posix/Clock.h8
-rw-r--r--rts/posix/GetEnv.c10
-rw-r--r--rts/posix/GetTime.c51
-rw-r--r--rts/posix/Itimer.c18
-rw-r--r--rts/posix/Itimer.h8
-rw-r--r--rts/posix/OSMem.c41
-rw-r--r--rts/posix/OSThreads.c53
-rw-r--r--rts/posix/Select.c179
-rw-r--r--rts/posix/Select.h8
-rw-r--r--rts/posix/Signals.c137
-rw-r--r--rts/posix/Signals.h7
-rw-r--r--rts/posix/TTY.c40
-rw-r--r--rts/posix/TTY.h8
13 files changed, 350 insertions, 218 deletions
diff --git a/rts/posix/Clock.h b/rts/posix/Clock.h
index 2c71d7a75d..16d9252460 100644
--- a/rts/posix/Clock.h
+++ b/rts/posix/Clock.h
@@ -33,3 +33,11 @@
#endif
#endif /* POSIX_CLOCK_H */
+
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/GetEnv.c b/rts/posix/GetEnv.c
index 4d5c7e248e..de6d5cd989 100644
--- a/rts/posix/GetEnv.c
+++ b/rts/posix/GetEnv.c
@@ -32,7 +32,7 @@ static char** get_environ(void) { return environ; }
void getProgEnvv(int *out_envc, char **out_envv[]) {
int envc;
char **environ = get_environ();
-
+
for (envc = 0; environ[envc] != NULL; envc++) {};
*out_envc = envc;
@@ -42,3 +42,11 @@ void getProgEnvv(int *out_envc, char **out_envv[]) {
void freeProgEnvv(int envc STG_UNUSED, char *envv[] STG_UNUSED) {
/* nothing */
}
+
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/GetTime.c b/rts/posix/GetTime.c
index 380e22931b..d44fc9a566 100644
--- a/rts/posix/GetTime.c
+++ b/rts/posix/GetTime.c
@@ -50,7 +50,11 @@ void initializeTimer()
Time getProcessCPUTime(void)
{
-#if !defined(BE_CONSERVATIVE) && defined(HAVE_CLOCK_GETTIME) && defined (_SC_CPUTIME) && defined(CLOCK_PROCESS_CPUTIME_ID) && defined(HAVE_SYSCONF)
+#if !defined(BE_CONSERVATIVE) && \
+ defined(HAVE_CLOCK_GETTIME) && \
+ defined(_SC_CPUTIME) && \
+ defined(CLOCK_PROCESS_CPUTIME_ID) && \
+ defined(HAVE_SYSCONF)
static int checked_sysconf = 0;
static int sysconf_result = 0;
@@ -129,7 +133,7 @@ Time getProcessCPUTime(void)
#if !defined(THREADED_RTS) && USE_PAPI
long long usec;
if ((usec = PAPI_get_virt_usec()) < 0) {
- barf("PAPI_get_virt_usec: %lld", usec);
+ barf("PAPI_get_virt_usec: %lld", usec);
}
return USToTime(usec);
#else
@@ -152,22 +156,22 @@ void getProcessTimes(Time *user, Time *elapsed)
if (ClockFreq == 0) {
#if defined(HAVE_SYSCONF)
- long ticks;
- ticks = sysconf(_SC_CLK_TCK);
- if ( ticks == -1 ) {
- sysErrorBelch("sysconf");
- stg_exit(EXIT_FAILURE);
- }
- ClockFreq = ticks;
-#elif defined(CLK_TCK) /* defined by POSIX */
- ClockFreq = CLK_TCK;
+ long ticks;
+ ticks = sysconf(_SC_CLK_TCK);
+ if ( ticks == -1 ) {
+ sysErrorBelch("sysconf");
+ stg_exit(EXIT_FAILURE);
+ }
+ ClockFreq = ticks;
+#elif defined(CLK_TCK) /* defined by POSIX */
+ ClockFreq = CLK_TCK;
#elif defined(HZ)
- ClockFreq = HZ;
+ ClockFreq = HZ;
#elif defined(CLOCKS_PER_SEC)
- ClockFreq = CLOCKS_PER_SEC;
+ ClockFreq = CLOCKS_PER_SEC;
#else
- errorBelch("can't get clock resolution");
- stg_exit(EXIT_FAILURE);
+ errorBelch("can't get clock resolution");
+ stg_exit(EXIT_FAILURE);
#endif
}
@@ -184,15 +188,19 @@ Time getThreadCPUTime(void)
#if USE_PAPI
long long usec;
if ((usec = PAPI_get_virt_usec()) < 0) {
- barf("PAPI_get_virt_usec: %lld", usec);
+ barf("PAPI_get_virt_usec: %lld", usec);
}
return USToTime(usec);
-#elif !defined(BE_CONSERVATIVE) && defined(HAVE_CLOCK_GETTIME) && defined (_SC_THREAD_CPUTIME) && defined(CLOCK_THREAD_CPUTIME_ID) && defined(HAVE_SYSCONF)
+#elif !defined(BE_CONSERVATIVE) && \
+ defined(HAVE_CLOCK_GETTIME) && \
+ defined(_SC_CPUTIME) && \
+ defined(CLOCK_PROCESS_CPUTIME_ID) && \
+ defined(HAVE_SYSCONF)
{
static int checked_sysconf = 0;
static int sysconf_result = 0;
-
+
if (!checked_sysconf) {
sysconf_result = sysconf(_SC_THREAD_CPUTIME);
checked_sysconf = 1;
@@ -240,3 +248,10 @@ getPageFaults(void)
#endif
}
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/Itimer.c b/rts/posix/Itimer.c
index 4bcc3a1c2e..f8b9f66d4d 100644
--- a/rts/posix/Itimer.c
+++ b/rts/posix/Itimer.c
@@ -9,10 +9,10 @@
/*
* The interval timer is used for profiling and for context switching in the
* threaded build. Though POSIX 1003.1b includes a standard interface for
- * such things, no one really seems to be implementing them yet. Even
+ * such things, no one really seems to be implementing them yet. Even
* Solaris 2.3 only seems to provide support for @CLOCK_REAL@, whereas we're
* keen on getting access to @CLOCK_VIRTUAL@.
- *
+ *
* Hence, we use the old-fashioned @setitimer@ that just about everyone seems
* to support. So much for standards.
*/
@@ -202,11 +202,11 @@ startTicker(void)
#elif defined(USE_TIMER_CREATE)
{
struct itimerspec it;
-
+
it.it_value.tv_sec = TimeToSeconds(itimer_interval);
it.it_value.tv_nsec = TimeToNS(itimer_interval) % 1000000000;
it.it_interval = it.it_value;
-
+
if (timer_settime(timer, 0, &it, NULL) != 0) {
sysErrorBelch("timer_settime");
stg_exit(EXIT_FAILURE);
@@ -219,7 +219,7 @@ startTicker(void)
it.it_value.tv_sec = TimeToSeconds(itimer_interval);
it.it_value.tv_usec = TimeToUS(itimer_interval) % 1000000;
it.it_interval = it.it_value;
-
+
if (setitimer(ITIMER_REAL, &it, NULL) != 0) {
sysErrorBelch("setitimer");
stg_exit(EXIT_FAILURE);
@@ -280,3 +280,11 @@ rtsTimerSignal(void)
{
return ITIMER_SIGNAL;
}
+
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/Itimer.h b/rts/posix/Itimer.h
index 7996da7c94..3ca2f5b097 100644
--- a/rts/posix/Itimer.h
+++ b/rts/posix/Itimer.h
@@ -10,3 +10,11 @@
#define ITIMER_H
#endif /* ITIMER_H */
+
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/OSMem.c b/rts/posix/OSMem.c
index 69140a914c..eb51e98e72 100644
--- a/rts/posix/OSMem.c
+++ b/rts/posix/OSMem.c
@@ -81,13 +81,13 @@ my_mmap (void *addr, W_ size)
void *ret;
#if defined(solaris2_HOST_OS) || defined(irix_HOST_OS)
- {
+ {
int fd = open("/dev/zero",O_RDONLY);
ret = mmap(addr, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
close(fd);
}
#elif hpux_HOST_OS
- ret = mmap(addr, size, PROT_READ | PROT_WRITE,
+ ret = mmap(addr, size, PROT_READ | PROT_WRITE,
MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
#elif darwin_HOST_OS
// Without MAP_FIXED, Apple's mmap ignores addr.
@@ -97,21 +97,23 @@ my_mmap (void *addr, W_ size)
// This behaviour seems to be conformant with IEEE Std 1003.1-2001.
// Let's just use the underlying Mach Microkernel calls directly,
// they're much nicer.
-
+
kern_return_t err = 0;
ret = addr;
if(addr) // try to allocate at address
err = vm_allocate(mach_task_self(),(vm_address_t*) &ret, size, FALSE);
if(!addr || err) // try to allocate anywhere
err = vm_allocate(mach_task_self(),(vm_address_t*) &ret, size, TRUE);
-
+
if(err) {
// don't know what the error codes mean exactly, assume it's
// not our problem though.
- errorBelch("memory allocation failed (requested %" FMT_Word " bytes)", size);
+ errorBelch("memory allocation failed (requested %" FMT_Word " bytes)",
+ size);
stg_exit(EXIT_FAILURE);
} else {
- vm_protect(mach_task_self(),(vm_address_t)ret,size,FALSE,VM_PROT_READ|VM_PROT_WRITE);
+ vm_protect(mach_task_self(), (vm_address_t)ret, size, FALSE,
+ VM_PROT_READ|VM_PROT_WRITE);
}
#elif linux_HOST_OS
ret = mmap(addr, size, PROT_READ | PROT_WRITE,
@@ -135,12 +137,12 @@ my_mmap (void *addr, W_ size)
}
}
#else
- ret = mmap(addr, size, PROT_READ | PROT_WRITE,
+ ret = mmap(addr, size, PROT_READ | PROT_WRITE,
MAP_ANON | MAP_PRIVATE, -1, 0);
#endif
if (ret == (void *)-1) {
- if (errno == ENOMEM ||
+ if (errno == ENOMEM ||
(errno == EINVAL && sizeof(void*)==4 && size >= 0xc0000000)) {
// If we request more than 3Gig, then we get EINVAL
// instead of ENOMEM (at least on Linux).
@@ -167,10 +169,10 @@ gen_map_mblocks (W_ size)
// it (unmap the rest).
size += MBLOCK_SIZE;
ret = my_mmap(0, size);
-
+
// unmap the slop bits around the chunk we allocated
slop = (W_)ret & MBLOCK_MASK;
-
+
if (munmap((void*)ret, MBLOCK_SIZE - slop) == -1) {
barf("gen_map_mblocks: munmap failed");
}
@@ -188,7 +190,7 @@ gen_map_mblocks (W_ size)
// you unmap the extra mblock mmap()ed here (or simply
// satisfy yourself that the slop introduced isn't worth
// salvaging.)
- //
+ //
// next time, try after the block we just got.
ret += MBLOCK_SIZE - slop;
@@ -210,7 +212,9 @@ osGetMBlocks(nat n)
if (((W_)ret & MBLOCK_MASK) != 0) {
// misaligned block!
#if 0 // defined(DEBUG)
- errorBelch("warning: getMBlock: misaligned block %p returned when allocating %d megablock(s) at %p", ret, n, next_request);
+ errorBelch("warning: getMBlock: misaligned block %p returned "
+ "when allocating %d megablock(s) at %p",
+ ret, n, next_request);
#endif
// unmap this block...
@@ -289,7 +293,8 @@ StgWord64 getPhysicalMemorySize (void)
long ret = sysconf(_SC_PHYS_PAGES);
if (ret == -1) {
#if defined(DEBUG)
- errorBelch("warning: getPhysicalMemorySize: cannot get physical memory size");
+ errorBelch("warning: getPhysicalMemorySize: cannot get "
+ "physical memory size");
#endif
return 0;
}
@@ -308,8 +313,16 @@ void setExecutable (void *p, W_ len, rtsBool exec)
StgWord startOfFirstPage = ((StgWord)p ) & mask;
StgWord startOfLastPage = ((StgWord)p + len - 1) & mask;
StgWord size = startOfLastPage - startOfFirstPage + pageSize;
- if (mprotect((void*)startOfFirstPage, (size_t)size,
+ if (mprotect((void*)startOfFirstPage, (size_t)size,
(exec ? PROT_EXEC : 0) | PROT_READ | PROT_WRITE) != 0) {
barf("setExecutable: failed to protect 0x%p\n", p);
}
}
+
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/OSThreads.c b/rts/posix/OSThreads.c
index 13a176c9d2..f42b4e964c 100644
--- a/rts/posix/OSThreads.c
+++ b/rts/posix/OSThreads.c
@@ -3,7 +3,7 @@
* (c) The GHC Team, 2001-2005
*
* Accessing OS threads functionality in a (mostly) OS-independent
- * manner.
+ * manner.
*
* --------------------------------------------------------------------------*/
@@ -18,7 +18,7 @@
#if defined(freebsd_HOST_OS)
/* Inclusion of system headers usually requires __BSD_VISIBLE on FreeBSD,
* because of some specific types, like u_char, u_int, etc. */
-#define __BSD_VISIBLE 1
+#define __BSD_VISIBLE 1
#endif
#include "Rts.h"
@@ -175,7 +175,7 @@ newThreadLocalKey (ThreadLocalKey *key)
{
int r;
if ((r = pthread_key_create(key, NULL)) != 0) {
- barf("newThreadLocalKey: %s", strerror(r));
+ barf("newThreadLocalKey: %s", strerror(r));
}
}
@@ -194,7 +194,7 @@ setThreadLocalVar (ThreadLocalKey *key, void *value)
{
int r;
if ((r = pthread_setspecific(*key,value)) != 0) {
- barf("setThreadLocalVar: %s", strerror(r));
+ barf("setThreadLocalVar: %s", strerror(r));
}
}
@@ -203,7 +203,7 @@ freeThreadLocalKey (ThreadLocalKey *key)
{
int r;
if ((r = pthread_key_delete(*key)) != 0) {
- barf("freeThreadLocalKey: %s", strerror(r));
+ barf("freeThreadLocalKey: %s", strerror(r));
}
}
@@ -222,7 +222,7 @@ forkOS_createThread ( HsStablePtr entry )
{
pthread_t tid;
int result = pthread_create(&tid, NULL,
- forkOS_createThreadWrapper, (void*)entry);
+ forkOS_createThreadWrapper, (void*)entry);
if(!result)
pthread_detach(tid);
return result;
@@ -277,33 +277,34 @@ setThreadAffinity (nat n, nat m GNUC3_ATTRIBUTE(__unused__))
thread_affinity_policy_data_t policy;
policy.affinity_tag = n;
- thread_policy_set(mach_thread_self(),
- THREAD_AFFINITY_POLICY,
- (thread_policy_t) &policy,
- THREAD_AFFINITY_POLICY_COUNT);
+ thread_policy_set(mach_thread_self(),
+ THREAD_AFFINITY_POLICY,
+ (thread_policy_t) &policy,
+ THREAD_AFFINITY_POLICY_COUNT);
}
#elif defined(HAVE_SYS_CPUSET_H) /* FreeBSD 7.1+ */
void
setThreadAffinity(nat n, nat m)
{
- nat nproc;
- cpuset_t cs;
- nat i;
+ nat nproc;
+ cpuset_t cs;
+ nat i;
- nproc = getNumberOfProcessors();
- CPU_ZERO(&cs);
+ nproc = getNumberOfProcessors();
+ CPU_ZERO(&cs);
- for (i = n; i < nproc; i += m)
- CPU_SET(i, &cs);
+ for (i = n; i < nproc; i += m)
+ CPU_SET(i, &cs);
- cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), &cs);
+ cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID,
+ -1, sizeof(cpuset_t), &cs);
}
#else
void
-setThreadAffinity (nat n GNUC3_ATTRIBUTE(__unused__),
- nat m GNUC3_ATTRIBUTE(__unused__))
+setThreadAffinity (nat n GNUC3_ATTRIBUTE(__unused__),
+ nat m GNUC3_ATTRIBUTE(__unused__))
{
}
#endif
@@ -340,7 +341,9 @@ KernelThreadId kernelThreadId (void)
return pthread_getthreadid_np();
// Check for OS X >= 10.6 (see #7356)
-#elif defined(darwin_HOST_OS) && !(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
+#elif defined(darwin_HOST_OS) && \
+ !(defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
+ __MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
uint64_t ktid;
pthread_threadid_np(NULL, &ktid);
return ktid;
@@ -350,3 +353,11 @@ KernelThreadId kernelThreadId (void)
return 0;
#endif
}
+
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/Select.c b/rts/posix/Select.c
index a101f03dd5..29a1dd144d 100644
--- a/rts/posix/Select.c
+++ b/rts/posix/Select.c
@@ -100,17 +100,18 @@ static rtsBool wakeUpSleepingThreads (LowResTime now)
rtsBool flag = rtsFalse;
while (sleeping_queue != END_TSO_QUEUE) {
- tso = sleeping_queue;
+ tso = sleeping_queue;
if (((long)now - (long)tso->block_info.target) < 0) {
break;
}
- sleeping_queue = tso->_link;
- tso->why_blocked = NotBlocked;
- tso->_link = END_TSO_QUEUE;
- IF_DEBUG(scheduler,debugBelch("Waking up sleeping thread %lu\n", (unsigned long)tso->id));
- // MainCapability: this code is !THREADED_RTS
- pushOnRunQueue(&MainCapability,tso);
- flag = rtsTrue;
+ sleeping_queue = tso->_link;
+ tso->why_blocked = NotBlocked;
+ tso->_link = END_TSO_QUEUE;
+ IF_DEBUG(scheduler, debugBelch("Waking up sleeping thread %lu\n",
+ (unsigned long)tso->id));
+ // MainCapability: this code is !THREADED_RTS
+ pushOnRunQueue(&MainCapability,tso);
+ flag = rtsTrue;
}
return flag;
}
@@ -118,7 +119,9 @@ static rtsBool wakeUpSleepingThreads (LowResTime now)
static void GNUC3_ATTRIBUTE(__noreturn__)
fdOutOfRange (int fd)
{
- errorBelch("file descriptor %d out of range for select (0--%d).\nRecompile with -threaded to work around this.", fd, (int)FD_SETSIZE);
+ errorBelch("file descriptor %d out of range for select (0--%d).\n"
+ "Recompile with -threaded to work around this.",
+ fd, (int)FD_SETSIZE);
stg_exit(EXIT_FAILURE);
}
@@ -226,12 +229,12 @@ awaitEvent(rtsBool wait)
LowResTime now;
IF_DEBUG(scheduler,
- debugBelch("scheduler: checking for threads blocked on I/O");
- if (wait) {
- debugBelch(" (waiting)");
- }
- debugBelch("\n");
- );
+ debugBelch("scheduler: checking for threads blocked on I/O");
+ if (wait) {
+ debugBelch(" (waiting)");
+ }
+ debugBelch("\n");
+ );
/* loop until we've woken up some threads. This loop is needed
* because the select timing isn't accurate, we sometimes sleep
@@ -242,7 +245,7 @@ awaitEvent(rtsBool wait)
now = getLowResTimeOfDay();
if (wakeUpSleepingThreads(now)) {
- return;
+ return;
}
/*
@@ -252,38 +255,38 @@ awaitEvent(rtsBool wait)
FD_ZERO(&wfd);
for(tso = blocked_queue_hd; tso != END_TSO_QUEUE; tso = next) {
- next = tso->_link;
+ next = tso->_link;
/* On FreeBSD FD_SETSIZE is unsigned. Cast it to signed int
* in order to switch off the 'comparison between signed and
* unsigned error message
*/
- switch (tso->why_blocked) {
- case BlockedOnRead:
- {
- int fd = tso->block_info.fd;
- if ((fd >= (int)FD_SETSIZE) || (fd < 0)) {
+ switch (tso->why_blocked) {
+ case BlockedOnRead:
+ {
+ int fd = tso->block_info.fd;
+ if ((fd >= (int)FD_SETSIZE) || (fd < 0)) {
fdOutOfRange(fd);
- }
- maxfd = (fd > maxfd) ? fd : maxfd;
- FD_SET(fd, &rfd);
- continue;
- }
-
- case BlockedOnWrite:
- {
- int fd = tso->block_info.fd;
- if ((fd >= (int)FD_SETSIZE) || (fd < 0)) {
+ }
+ maxfd = (fd > maxfd) ? fd : maxfd;
+ FD_SET(fd, &rfd);
+ continue;
+ }
+
+ case BlockedOnWrite:
+ {
+ int fd = tso->block_info.fd;
+ if ((fd >= (int)FD_SETSIZE) || (fd < 0)) {
fdOutOfRange(fd);
- }
- maxfd = (fd > maxfd) ? fd : maxfd;
- FD_SET(fd, &wfd);
- continue;
- }
-
- default:
- barf("AwaitEvent");
- }
+ }
+ maxfd = (fd > maxfd) ? fd : maxfd;
+ FD_SET(fd, &wfd);
+ continue;
+ }
+
+ default:
+ barf("AwaitEvent");
+ }
}
if (!wait) {
@@ -301,46 +304,46 @@ awaitEvent(rtsBool wait)
}
/* Check for any interesting events */
-
+
while ((numFound = select(maxfd+1, &rfd, &wfd, NULL, ptv)) < 0) {
- if (errno != EINTR) {
- if ( errno == EBADF ) {
+ if (errno != EINTR) {
+ if ( errno == EBADF ) {
seen_bad_fd = rtsTrue;
break;
- } else {
+ } else {
sysErrorBelch("select");
stg_exit(EXIT_FAILURE);
}
- }
+ }
- /* We got a signal; could be one of ours. If so, we need
- * to start up the signal handler straight away, otherwise
- * we could block for a long time before the signal is
- * serviced.
- */
+ /* We got a signal; could be one of ours. If so, we need
+ * to start up the signal handler straight away, otherwise
+ * we could block for a long time before the signal is
+ * serviced.
+ */
#if defined(RTS_USER_SIGNALS)
- if (RtsFlags.MiscFlags.install_signal_handlers && signals_pending()) {
- startSignalHandlers(&MainCapability);
- return; /* still hold the lock */
- }
+ if (RtsFlags.MiscFlags.install_signal_handlers && signals_pending()) {
+ startSignalHandlers(&MainCapability);
+ return; /* still hold the lock */
+ }
#endif
- /* we were interrupted, return to the scheduler immediately.
- */
- if (sched_state >= SCHED_INTERRUPTING) {
- return; /* still hold the lock */
- }
-
- /* check for threads that need waking up
- */
+ /* we were interrupted, return to the scheduler immediately.
+ */
+ if (sched_state >= SCHED_INTERRUPTING) {
+ return; /* still hold the lock */
+ }
+
+ /* check for threads that need waking up
+ */
wakeUpSleepingThreads(getLowResTimeOfDay());
- /* If new runnable threads have arrived, stop waiting for
- * I/O and run them.
- */
- if (!emptyRunQueue(&MainCapability)) {
- return; /* still hold the lock */
- }
+ /* If new runnable threads have arrived, stop waiting for
+ * I/O and run them.
+ */
+ if (!emptyRunQueue(&MainCapability)) {
+ return; /* still hold the lock */
+ }
}
/* Step through the waiting queue, unblocking every thread that now has
@@ -383,11 +386,16 @@ awaitEvent(rtsBool wait)
* Don't let RTS loop on such descriptors,
* pass an IOError to blocked threads (Trac #4934)
*/
- IF_DEBUG(scheduler,debugBelch("Killing blocked thread %lu on bad fd=%i\n", (unsigned long)tso->id, fd));
- throwToSingleThreaded(&MainCapability, tso, (StgClosure *)blockedOnBadFD_closure);
+ IF_DEBUG(scheduler,
+ debugBelch("Killing blocked thread %lu on bad fd=%i\n",
+ (unsigned long)tso->id, fd));
+ throwToSingleThreaded(&MainCapability, tso,
+ (StgClosure *)blockedOnBadFD_closure);
break;
case RTS_FD_IS_READY:
- IF_DEBUG(scheduler,debugBelch("Waking up blocked thread %lu\n", (unsigned long)tso->id));
+ IF_DEBUG(scheduler,
+ debugBelch("Waking up blocked thread %lu\n",
+ (unsigned long)tso->id));
tso->why_blocked = NotBlocked;
tso->_link = END_TSO_QUEUE;
pushOnRunQueue(&MainCapability,tso);
@@ -400,19 +408,26 @@ awaitEvent(rtsBool wait)
prev = tso;
break;
}
- }
-
- if (prev == NULL)
- blocked_queue_hd = blocked_queue_tl = END_TSO_QUEUE;
- else {
- prev->_link = END_TSO_QUEUE;
- blocked_queue_tl = prev;
- }
+ }
+
+ if (prev == NULL)
+ blocked_queue_hd = blocked_queue_tl = END_TSO_QUEUE;
+ else {
+ prev->_link = END_TSO_QUEUE;
+ blocked_queue_tl = prev;
+ }
}
-
+
} while (wait && sched_state == SCHED_RUNNING
- && emptyRunQueue(&MainCapability));
+ && emptyRunQueue(&MainCapability));
}
#endif /* THREADED_RTS */
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/Select.h b/rts/posix/Select.h
index 50d49d4ba5..b63e45a1ae 100644
--- a/rts/posix/Select.h
+++ b/rts/posix/Select.h
@@ -15,3 +15,11 @@ typedef StgWord LowResTime;
RTS_PRIVATE LowResTime getDelayTarget (HsInt us);
#endif /* POSIX_SELECT_H */
+
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/Signals.c b/rts/posix/Signals.c
index f4a8341c6a..d5129f0996 100644
--- a/rts/posix/Signals.c
+++ b/rts/posix/Signals.c
@@ -6,7 +6,7 @@
*
* ---------------------------------------------------------------------------*/
-#include "PosixSource.h"
+#include "PosixSource.h"
#include "Rts.h"
#include "Schedule.h"
@@ -49,7 +49,7 @@
/* This curious flag is provided for the benefit of the Haskell binding
* to POSIX.1 to control whether or not to include SA_NOCLDSTOP when
- * installing a SIGCHLD handler.
+ * installing a SIGCHLD handler.
*/
HsInt nocldstop = 0;
@@ -108,16 +108,19 @@ more_handlers(int sig)
StgInt i;
if (sig < nHandlers)
- return;
+ return;
if (signal_handlers == NULL)
- signal_handlers = (StgInt *)stgMallocBytes((sig + 1) * sizeof(StgInt), "more_handlers");
+ signal_handlers = (StgInt *)stgMallocBytes((sig + 1) * sizeof(StgInt),
+ "more_handlers");
else
- signal_handlers = (StgInt *)stgReallocBytes(signal_handlers, (sig + 1) * sizeof(StgInt), "more_handlers");
+ signal_handlers = (StgInt *)stgReallocBytes(signal_handlers,
+ (sig + 1) * sizeof(StgInt),
+ "more_handlers");
for(i = nHandlers; i <= sig; i++)
- // Fill in the new slots with default actions
- signal_handlers[i] = STG_SIG_DFL;
+ // Fill in the new slots with default actions
+ signal_handlers[i] = STG_SIG_DFL;
nHandlers = sig + 1;
}
@@ -153,11 +156,11 @@ ioManagerWakeup (void)
// Wake up the IO Manager thread by sending a byte down its pipe
if (io_manager_wakeup_fd >= 0) {
#if defined(HAVE_EVENTFD)
- StgWord64 n = (StgWord64)IO_MANAGER_WAKEUP;
- r = write(io_manager_wakeup_fd, (char *) &n, 8);
+ StgWord64 n = (StgWord64)IO_MANAGER_WAKEUP;
+ r = write(io_manager_wakeup_fd, (char *) &n, 8);
#else
- StgWord8 byte = (StgWord8)IO_MANAGER_WAKEUP;
- r = write(io_manager_wakeup_fd, &byte, 1);
+ StgWord8 byte = (StgWord8)IO_MANAGER_WAKEUP;
+ r = write(io_manager_wakeup_fd, &byte, 1);
#endif
if (r == -1) { sysErrorBelch("ioManagerWakeup: write"); }
}
@@ -170,8 +173,8 @@ ioManagerDie (void)
int r;
// Ask the IO Manager thread to exit
if (io_manager_control_fd >= 0) {
- StgWord8 byte = (StgWord8)IO_MANAGER_DIE;
- r = write(io_manager_control_fd, &byte, 1);
+ StgWord8 byte = (StgWord8)IO_MANAGER_DIE;
+ r = write(io_manager_control_fd, &byte, 1);
if (r == -1) { sysErrorBelch("ioManagerDie: write"); }
io_manager_control_fd = -1;
io_manager_wakeup_fd = -1;
@@ -190,9 +193,9 @@ ioManagerStart (void)
// Make sure the IO manager thread is running
Capability *cap;
if (io_manager_control_fd < 0 || io_manager_wakeup_fd < 0) {
- cap = rts_lock();
+ cap = rts_lock();
ioManagerStartCap(&cap);
- rts_unlock(cap);
+ rts_unlock(cap);
}
}
#endif
@@ -227,14 +230,14 @@ generic_handler(int sig USED_IF_THREADS,
buf[0] = sig;
- if (info == NULL) {
- // info may be NULL on Solaris (see #3790)
- memset(buf+1, 0, sizeof(siginfo_t));
- } else {
- memcpy(buf+1, info, sizeof(siginfo_t));
- }
+ if (info == NULL) {
+ // info may be NULL on Solaris (see #3790)
+ memset(buf+1, 0, sizeof(siginfo_t));
+ } else {
+ memcpy(buf+1, info, sizeof(siginfo_t));
+ }
- r = write(io_manager_control_fd, buf, sizeof(siginfo_t)+1);
+ r = write(io_manager_control_fd, buf, sizeof(siginfo_t)+1);
if (r == -1 && errno == EAGAIN)
{
errorBelch("lost signal due to full pipe: %d\n", sig);
@@ -255,7 +258,7 @@ generic_handler(int sig USED_IF_THREADS,
We need some kind of locking, but with low overhead (i.e. no
blocking signals every time around the scheduler).
-
+
Signal Handlers are atomic (i.e. they can't be interrupted), and
we can make use of this. We just need to make sure the
critical section of the scheduler can't be interrupted - the
@@ -264,14 +267,14 @@ generic_handler(int sig USED_IF_THREADS,
handlers to run, i.e. the set of pending handlers is
non-empty.
*/
-
+
/* We use a stack to store the pending signals. We can't
dynamically grow this since we can't allocate any memory from
within a signal handler.
Hence unfortunately we have to bomb out if the buffer
overflows. It might be acceptable to carry on in certain
- circumstances, depending on the signal.
+ circumstances, depending on the signal.
*/
memcpy(next_pending_handler, info, sizeof(siginfo_t));
@@ -280,10 +283,10 @@ generic_handler(int sig USED_IF_THREADS,
// stack full?
if (next_pending_handler == &pending_handler_buf[N_PENDING_HANDLERS]) {
- errorBelch("too many pending signals");
- stg_exit(EXIT_FAILURE);
+ errorBelch("too many pending signals");
+ stg_exit(EXIT_FAILURE);
}
-
+
interruptCapability(&MainCapability);
#endif /* THREADED_RTS */
@@ -316,7 +319,7 @@ void
awaitUserSignals(void)
{
while (!signals_pending() && sched_state == SCHED_RUNNING) {
- pause();
+ pause();
}
}
#endif
@@ -340,34 +343,36 @@ stg_sig_install(int sig, int spi, void *mask)
// Block the signal until we figure out what to do
// Count on this to fail if the signal number is invalid
- if (sig < 0 || sigemptyset(&signals) ||
- sigaddset(&signals, sig) || sigprocmask(SIG_BLOCK, &signals, &osignals)) {
+ if (sig < 0 ||
+ sigemptyset(&signals) ||
+ sigaddset(&signals, sig) ||
+ sigprocmask(SIG_BLOCK, &signals, &osignals)) {
RELEASE_LOCK(&sig_mutex);
return STG_SIG_ERR;
}
-
+
more_handlers(sig);
previous_spi = signal_handlers[sig];
action.sa_flags = 0;
-
+
switch(spi) {
case STG_SIG_IGN:
action.sa_handler = SIG_IGN;
- break;
+ break;
case STG_SIG_DFL:
action.sa_handler = SIG_DFL;
- break;
+ break;
case STG_SIG_RST:
action.sa_flags |= SA_RESETHAND;
/* fall through */
case STG_SIG_HAN:
- action.sa_sigaction = generic_handler;
+ action.sa_sigaction = generic_handler;
action.sa_flags |= SA_SIGINFO;
- break;
+ break;
default:
barf("stg_sig_install: bad spi");
@@ -376,7 +381,7 @@ stg_sig_install(int sig, int spi, void *mask)
if (mask != NULL)
action.sa_mask = *(sigset_t *)mask;
else
- sigemptyset(&action.sa_mask);
+ sigemptyset(&action.sa_mask);
action.sa_flags |= sig == SIGCHLD && nocldstop ? SA_NOCLDSTOP : 0;
@@ -392,14 +397,14 @@ stg_sig_install(int sig, int spi, void *mask)
switch(spi) {
case STG_SIG_RST:
case STG_SIG_HAN:
- sigaddset(&userSignals, sig);
+ sigaddset(&userSignals, sig);
if (previous_spi != STG_SIG_HAN && previous_spi != STG_SIG_RST) {
n_haskell_handlers++;
}
- break;
+ break;
default:
- sigdelset(&userSignals, sig);
+ sigdelset(&userSignals, sig);
if (previous_spi == STG_SIG_HAN || previous_spi == STG_SIG_RST) {
n_haskell_handlers--;
}
@@ -429,7 +434,7 @@ startSignalHandlers(Capability *cap)
int sig;
blockUserSignals();
-
+
while (next_pending_handler != pending_handler_buf) {
next_pending_handler--;
@@ -439,18 +444,18 @@ startSignalHandlers(Capability *cap)
continue; // handler has been changed.
}
- info = stgMallocBytes(sizeof(siginfo_t), "startSignalHandlers");
+ info = stgMallocBytes(sizeof(siginfo_t), "startSignalHandlers");
// freed by runHandler
memcpy(info, next_pending_handler, sizeof(siginfo_t));
- scheduleThread (cap,
- createIOThread(cap,
- RtsFlags.GcFlags.initialStkSize,
- rts_apply(cap,
- rts_apply(cap,
- &base_GHCziConcziSignal_runHandlers_closure,
- rts_mkPtr(cap, info)),
- rts_mkInt(cap, info->si_signo))));
+ scheduleThread(cap,
+ createIOThread(cap,
+ RtsFlags.GcFlags.initialStkSize,
+ rts_apply(cap,
+ rts_apply(cap,
+ &base_GHCziConcziSignal_runHandlers_closure,
+ rts_mkPtr(cap, info)),
+ rts_mkInt(cap, info->si_signo))));
}
unblockUserSignals();
@@ -468,10 +473,10 @@ markSignalHandlers (evac_fn evac STG_UNUSED, void *user STG_UNUSED)
}
#else /* !RTS_USER_SIGNALS */
-StgInt
+StgInt
stg_sig_install(StgInt sig STG_UNUSED,
- StgInt spi STG_UNUSED,
- void* mask STG_UNUSED)
+ StgInt spi STG_UNUSED,
+ void* mask STG_UNUSED)
{
//barf("User signals not supported");
return STG_SIG_DFL;
@@ -493,9 +498,9 @@ shutdown_handler(int sig STG_UNUSED)
// extreme prejudice. So the first ^C tries to exit the program
// cleanly, and the second one just kills it.
if (sched_state >= SCHED_INTERRUPTING) {
- stg_exit(EXIT_INTERRUPTED);
+ stg_exit(EXIT_INTERRUPTED);
} else {
- interruptStgRts();
+ interruptStgRts();
}
}
@@ -604,11 +609,11 @@ initDefaultHandlers(void)
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
if (sigaction(SIGINT, &action, &oact) != 0) {
- sysErrorBelch("warning: failed to install SIGINT handler");
+ sysErrorBelch("warning: failed to install SIGINT handler");
}
#if defined(HAVE_SIGINTERRUPT)
- siginterrupt(SIGINT, 1); // isn't this the default? --SDM
+ siginterrupt(SIGINT, 1); // isn't this the default? --SDM
#endif
// install the SIGFPE handler
@@ -626,7 +631,7 @@ initDefaultHandlers(void)
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
if (sigaction(SIGFPE, &action, &oact) != 0) {
- sysErrorBelch("warning: failed to install SIGFPE handler");
+ sysErrorBelch("warning: failed to install SIGFPE handler");
}
#endif
@@ -641,7 +646,7 @@ initDefaultHandlers(void)
sigemptyset(&action.sa_mask);
action.sa_flags = 0;
if (sigaction(SIGPIPE, &action, &oact) != 0) {
- sysErrorBelch("warning: failed to install SIGPIPE handler");
+ sysErrorBelch("warning: failed to install SIGPIPE handler");
}
set_sigtstp_action(rtsTrue);
@@ -658,14 +663,22 @@ resetDefaultHandlers(void)
// restore SIGINT
if (sigaction(SIGINT, &action, NULL) != 0) {
- sysErrorBelch("warning: failed to uninstall SIGINT handler");
+ sysErrorBelch("warning: failed to uninstall SIGINT handler");
}
// restore SIGPIPE
if (sigaction(SIGPIPE, &action, NULL) != 0) {
- sysErrorBelch("warning: failed to uninstall SIGPIPE handler");
+ sysErrorBelch("warning: failed to uninstall SIGPIPE handler");
}
set_sigtstp_action(rtsFalse);
}
#endif /* RTS_USER_SIGNALS */
+
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/Signals.h b/rts/posix/Signals.h
index 387d688912..9500fceeb4 100644
--- a/rts/posix/Signals.h
+++ b/rts/posix/Signals.h
@@ -32,3 +32,10 @@ extern StgInt *signal_handlers;
#endif /* POSIX_SIGNALS_H */
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/TTY.c b/rts/posix/TTY.c
index d39ef37b86..009ebd6592 100644
--- a/rts/posix/TTY.c
+++ b/rts/posix/TTY.c
@@ -27,8 +27,9 @@ 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;
+ return (0 <= fd &&
+ fd < (int)(sizeof(saved_termios) / sizeof(*saved_termios))) ?
+ saved_termios[fd] : NULL;
}
void
@@ -47,19 +48,28 @@ resetTerminalSettings (void)
// 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);
+ {
+ 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
}
+
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
diff --git a/rts/posix/TTY.h b/rts/posix/TTY.h
index 7b8e16bb92..fe3e55b579 100644
--- a/rts/posix/TTY.h
+++ b/rts/posix/TTY.h
@@ -12,3 +12,11 @@
RTS_PRIVATE void resetTerminalSettings (void);
#endif /* POSIX_TTY_H */
+
+// Local Variables:
+// mode: C
+// fill-column: 80
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End: