]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
From Robert Collins:
authorhno <>
Sat, 17 Mar 2001 20:31:16 +0000 (20:31 +0000)
committerhno <>
Sat, 17 Mar 2001 20:31:16 +0000 (20:31 +0000)
I've implemented pthread_cond* in cygwin (available in the 1.3.0
code - CVS HEAD branch), so the native win32 threaded code is no longer
needed. The in-cygwin implementation runs the existing aufs code nearly
unaltered. The attached patch brings in the same file  mode details
already implemented in ufs for cygwin (O_BINARY), not unlinking open
files... and #if tests the scheduler settings which aren't present on
cygwin yet.

src/fs/aufs/aiops.cc
src/fs/aufs/store_dir_aufs.cc
src/fs/aufs/store_io_aufs.cc

index 3132a392d9f5bf7b7d65738482200bcc86e832f4..327456a0d2d4552b292afc78eb6f38033f0359ab 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: aiops.cc,v 1.7 2001/01/12 00:37:32 wessels Exp $
+ * $Id: aiops.cc,v 1.8 2001/03/17 13:31:16 hno Exp $
  *
  * DEBUG: section 43    AIOPS
  * AUTHOR: Stewart Forster <slf@connect.com.au>
@@ -169,7 +169,9 @@ static struct {
     NULL, &done_requests.head
 };
 static pthread_attr_t globattr;
+#if HAVE_SCHED_H
 static struct sched_param globsched;
+#endif
 static pthread_t main_thread;
 
 static MemPool *
@@ -254,13 +256,17 @@ aio_init(void)
 #if HAVE_PTHREAD_ATTR_SETSCOPE
     pthread_attr_setscope(&globattr, PTHREAD_SCOPE_SYSTEM);
 #endif
+#if HAVE_SCHED_H
     globsched.sched_priority = 1;
+#endif
     main_thread = pthread_self();
-#if HAVE_PTHREAD_SETSCHEDPARAM
+#if HAVE_SCHED_H && HAVE_PTHREAD_SETSCHEDPARAM
     pthread_setschedparam(main_thread, SCHED_OTHER, &globsched);
 #endif
+#if HAVE_SCHED_H
     globsched.sched_priority = 2;
-#if HAVE_PTHREAD_ATTR_SETSCHEDPARAM
+#endif
+#if HAVE_SCHED_H && HAVE_PTHREAD_ATTR_SETSCHEDPARAM
     pthread_attr_setschedparam(&globattr, &globsched);
 #endif
 
@@ -808,6 +814,7 @@ aio_poll_queues(void)
        }
        done_requests.tailp = &requests->next;
     }
+#if HAVE_SCHED_H
     /* Give up the CPU to allow the threads to do their work */
     /*
      * For Andres thoughts about yield(), see
@@ -819,6 +826,7 @@ aio_poll_queues(void)
 #else
        yield();
 #endif
+#endif
 }
 
 aio_result_t *
index a33cd4f79769fc5e1f4dea1e6a45672a85008b87..09af0ea573055688bda1791af7d544ce89877b87 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: store_dir_aufs.cc,v 1.33 2001/03/14 22:28:37 wessels Exp $
+ * $Id: store_dir_aufs.cc,v 1.34 2001/03/17 13:31:16 hno Exp $
  *
  * DEBUG: section 47    Store Directory Routines
  * AUTHOR: Duane Wessels
@@ -322,7 +322,7 @@ storeAufsDirOpenSwapLog(SwapDir * sd)
     char *path;
     int fd;
     path = storeAufsDirSwapLogFile(sd, NULL);
-    fd = file_open(path, O_WRONLY | O_CREAT);
+    fd = file_open(path, O_WRONLY | O_CREAT | O_BINARY);
     if (fd < 0) {
        debug(50, 1) ("%s: %s\n", path, xstrerror());
        fatal("storeAufsDirOpenSwapLog: Failed to open swap log.");
@@ -755,7 +755,7 @@ storeAufsDirGetNextFile(RebuildState * rb, int *sfileno, int *size)
            snprintf(rb->fullfilename, SQUID_MAXPATHLEN, "%s/%s",
                rb->fullpath, rb->entry->d_name);
            debug(20, 3) ("storeAufsDirGetNextFile: Opening %s\n", rb->fullfilename);
-           fd = file_open(rb->fullfilename, O_RDONLY);
+           fd = file_open(rb->fullfilename, O_RDONLY | O_BINARY);
            if (fd < 0)
                debug(50, 1) ("storeAufsDirGetNextFile: %s: %s\n", rb->fullfilename, xstrerror());
            else
@@ -864,7 +864,7 @@ storeAufsDirCloseTmpSwapLog(SwapDir * sd)
     char *new_path = xstrdup(storeAufsDirSwapLogFile(sd, ".new"));
     int fd;
     file_close(aioinfo->swaplog_fd);
-#ifdef _SQUID_OS2_
+#if defined (_SQUID_OS2_) || defined (_SQUID_CYGWIN_)
     if (unlink(swaplog_path) < 0) {
        debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror());
        fatal("storeAufsDirCloseTmpSwapLog: unlink failed");
@@ -873,7 +873,7 @@ storeAufsDirCloseTmpSwapLog(SwapDir * sd)
     if (xrename(new_path, swaplog_path) < 0) {
        fatal("storeAufsDirCloseTmpSwapLog: rename failed");
     }
-    fd = file_open(swaplog_path, O_WRONLY | O_CREAT);
+    fd = file_open(swaplog_path, O_WRONLY | O_CREAT | O_BINARY);
     if (fd < 0) {
        debug(50, 1) ("%s: %s\n", swaplog_path, xstrerror());
        fatal("storeAufsDirCloseTmpSwapLog: Failed to open swap log.");
@@ -919,6 +919,9 @@ storeAufsDirOpenTmpSwapLog(SwapDir * sd, int *clean_flag, int *zero_flag)
        debug(50, 0) ("%s: %s\n", swaplog_path, xstrerror());
        fatal("Failed to open swap log for reading");
     }
+#if defined(_SQUID_CYGWIN_)
+    setmode(fileno(fp), O_BINARY);
+#endif
     memset(&clean_sb, '\0', sizeof(struct stat));
     if (stat(clean_path, &clean_sb) < 0)
        *clean_flag = 0;
@@ -957,7 +960,7 @@ storeAufsDirWriteCleanStart(SwapDir * sd)
     sd->log.clean.write = NULL;
     sd->log.clean.state = NULL;
     state->new = xstrdup(storeAufsDirSwapLogFile(sd, ".clean"));
-    state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC);
+    state->fd = file_open(state->new, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY);
     if (state->fd < 0) {
        xfree(state->new);
        xfree(state);
@@ -968,7 +971,9 @@ storeAufsDirWriteCleanStart(SwapDir * sd)
     state->outbuf = xcalloc(CLEAN_BUF_SZ, 1);
     state->outbuf_offset = 0;
     state->walker = sd->repl->WalkInit(sd->repl);
+#if !(defined(_SQUID_OS2_) || defined (_SQUID_CYGWIN_))
     unlink(state->new);
+#endif
     unlink(state->cln);
     debug(20, 3) ("storeDirWriteCleanLogs: opened %s, FD %d\n",
        state->new, state->fd);
@@ -1036,6 +1041,7 @@ storeAufsDirWriteCleanEntry(SwapDir * sd, const StoreEntry * e)
 static void
 storeAufsDirWriteCleanDone(SwapDir * sd)
 {
+    int fd;
     struct _clean_state *state = sd->log.clean.state;
     if (NULL == state)
        return;
@@ -1057,24 +1063,26 @@ storeAufsDirWriteCleanDone(SwapDir * sd)
      * so we have to close before renaming.
      */
     storeAufsDirCloseSwapLog(sd);
+    /* save the fd value for a later test */
+    fd = state->fd;
     /* rename */
     if (state->fd >= 0) {
-#ifdef _SQUID_OS2_
+#if defined(_SQUID_OS2_) || defined (_SQUID_CYGWIN_)
        file_close(state->fd);
        state->fd = -1;
-       if (unlink(cur) < 0)
+       if (unlink(state->cur) < 0)
            debug(50, 0) ("storeDirWriteCleanLogs: unlinkd failed: %s, %s\n",
-               xstrerror(), cur);
+               xstrerror(), state->cur);
 #endif
        xrename(state->new, state->cur);
     }
     /* touch a timestamp file if we're not still validating */
     if (store_dirs_rebuilding)
        (void) 0;
-    else if (state->fd < 0)
+    else if (fd < 0)
        (void) 0;
     else
-       file_close(file_open(state->cln, O_WRONLY | O_CREAT | O_TRUNC));
+       file_close(file_open(state->cln, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY));
     /* close */
     safe_free(state->cur);
     safe_free(state->new);
index f3fc995428aa683cce8a24a0d4777217d3fdbe0e..e9afd72f699f2173128e84b71f42109f5ad19c6c 100644 (file)
@@ -47,7 +47,7 @@ storeAufsOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback,
        return NULL;
 #endif
 #if !ASYNC_OPEN
-    fd = file_open(path, O_RDONLY);
+    fd = file_open(path, O_RDONLY | O_BINARY);
     if (fd < 0) {
        debug(78, 3) ("storeAufsOpen: got failude (%d)\n", errno);
        return NULL;
@@ -67,7 +67,7 @@ storeAufsOpen(SwapDir * SD, StoreEntry * e, STFNCB * file_callback,
     cbdataLock(callback_data);
     Opening_FD++;
 #if ASYNC_OPEN
-    aioOpen(path, O_RDONLY, 0644, storeAufsOpenDone, sio);
+    aioOpen(path, O_RDONLY | O_BINARY, 0644, storeAufsOpenDone, sio);
 #else
     storeAufsOpenDone(fd, sio, fd, 0);
 #endif
@@ -102,7 +102,7 @@ storeAufsCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * c
        return NULL;
 #endif
 #if !ASYNC_CREATE
-    fd = file_open(path, O_WRONLY | O_CREAT | O_TRUNC);
+    fd = file_open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY);
     if (fd < 0) {
        debug(78, 3) ("storeAufsCreate: got failude (%d)\n", errno);
        return NULL;
@@ -115,14 +115,14 @@ storeAufsCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * c
     ((aiostate_t *) (sio->fsstate))->flags.opening = 1;
     sio->swap_filen = filn;
     sio->swap_dirn = dirn;
-    sio->mode = O_WRONLY;
+    sio->mode = O_WRONLY | O_BINARY;
     sio->callback = callback;
     sio->callback_data = callback_data;
     sio->e = (StoreEntry *) e;
     cbdataLock(callback_data);
     Opening_FD++;
 #if ASYNC_CREATE
-    aioOpen(path, O_WRONLY | O_CREAT | O_TRUNC, 0644, storeAufsOpenDone, sio);
+    aioOpen(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644, storeAufsOpenDone, sio);
 #else
     storeAufsOpenDone(fd, sio, fd, 0);
 #endif