Major file restructuring.
[cacao.git] / threads / threadio.c
index 21a01174f367e08561efd52cad401f653307b098..cc7b20b66feea92387372ac44c85b29145a5d379 100644 (file)
  * Written by Tim Wilkinson <tim@tjwassoc.demon.co.uk>, 1996.
  */
 
-#define        DBG(s)                    
-
-#include "config.h"
-
-#include "defines.h"
 
+#include <stdio.h>
 #include <sys/types.h>
 #include <sys/time.h>
 #include <sys/socket.h>
 #include <assert.h>
 #include <unistd.h>
 
+#include "config.h"
 #include "thread.h"
 
-/*
- * We only need this stuff is we are using the internal thread system.
- */
-#if defined(USE_INTERNAL_THREADS)
 
 #define        TH_READ         0
 #define        TH_WRITE        1
@@ -41,7 +34,6 @@ static fd_set readsPending;
 static fd_set writesPending;
 static thread* readQ[FD_SETSIZE];
 static thread* writeQ[FD_SETSIZE];
-static struct timeval tm = { 0, 0 };
 
 void blockOnFile(int, int);
 void waitOnEvents(void);
@@ -62,7 +54,9 @@ threadedFileDescriptor(int fd)
 {
 #if !defined(BLOCKING_CALLS)
     int r;
+#if defined(HAVE_IOCTL) && defined(FIOASYNC)
     int on = 1;
+#endif
     int pid;
 
     /* Make non-blocking */
@@ -112,35 +106,38 @@ threadedFileDescriptor(int fd)
 void clear_thread_flags(void)
 {
 #if !defined(BLOCKING_CALLS)
-       int fl, fd;
-
 #if defined(HAVE_FCNTL) && defined(O_NONBLOCK)
-       fd = fileno(stdin);
+    int fl, fd;
+
+    fd = fileno(stdin);
     fl = fcntl(fd, F_GETFL, 0);
     fl = fcntl(fd, F_SETFL, fl & (~O_NONBLOCK));
 
-       fd = fileno(stdout);
+    fd = fileno(stdout);
     fl = fcntl(fd, F_GETFL, 0);
     fl = fcntl(fd, F_SETFL, fl & (~O_NONBLOCK));
 
-       fd = fileno(stderr);
+    fd = fileno(stderr);
     fl = fcntl(fd, F_GETFL, 0);
     fl = fcntl(fd, F_SETFL, fl & (~O_NONBLOCK));
+
 #elif defined(HAVE_IOCTL) && defined(FIONBIO)
-       fl = 0;
-       fd = fileno(stdin);
+    int fl, fd;
+
+    fl = 0;
+    fd = fileno(stdin);
     (void) ioctl(fd, FIONBIO, &fl);
 
-       fd = fileno(stdout);
+    fd = fileno(stdout);
     (void) ioctl(fd, FIONBIO, &fl);
 
-       fd = fileno(stderr);
+    fd = fileno(stderr);
     (void) ioctl(fd, FIONBIO, &fl);
 #endif
-
 #endif
-fflush (stdout);
-fflush (stderr);
+
+    fflush(stdout);
+    fflush(stderr);
 }
 
 
@@ -151,9 +148,6 @@ int
 threadedSocket(int af, int type, int proto)
 {
     int fd;
-    int r;
-    int on = 1;
-    int pid;
 
     fd = socket(af, type, proto);
     return (threadedFileDescriptor(fd));
@@ -166,9 +160,6 @@ int
 threadedOpen(char* path, int flags, int mode)
 {
     int fd;
-    int r;
-    int on = 1;
-    int pid;
 
     fd = open(path, flags, mode);
     return (threadedFileDescriptor(fd));
@@ -202,7 +193,6 @@ int
 threadedAccept(int fd, struct sockaddr* addr, int* len)
 {
     int r;
-    int on = 1;
 
     for (;;)
     {
@@ -393,7 +383,7 @@ checkEvents(bool block)
 
     assert(blockInts > 0);
 
-DBG(   printf("checkEvents block:%d\n", block);                        )
+    DBG( printf("checkEvents block:%d\n", block); )
 
     if (sleepThreads != 0)
     {
@@ -444,7 +434,7 @@ DBG(        printf("checkEvents block:%d\n", block);                        )
      */
     assert(blockInts > 0);
 
-DBG(   printf("Select returns %d\n", r);                               )
+    DBG( printf("Select returns %d\n", r); )
 
     /* Some threads may have finished sleeping.
      */
@@ -485,4 +475,3 @@ DBG(        printf("Select returns %d\n", r);                               )
        }
     }
 }
-#endif