*** empty log message ***
authorMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 24 Nov 2005 07:13:39 +0000 (07:13 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Thu, 24 Nov 2005 07:13:39 +0000 (07:13 +0000)
mmsoftware/mmlib/mmsql.h
mmsoftware/mmmail/ChangeLog
mmsoftware/mmmail/GNUmakefile
mmsoftware/mmmail/src/mmpop3d/mmpop3d.c
mmsoftware/mmmail/src/mmpop3d/mmpop3d.h
mmsoftware/mmmail/src/mmsmtpd/mmsmtpd.c
mmsoftware/mmmail/src/mmsmtpd/mmsmtpd.h

index 0202e94..91619f7 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mmsql.h,v 1.8 2004/08/21 10:00:12 mmondor Exp $ */
+/* $Id: mmsql.h,v 1.8.2.1 2005/11/24 07:13:39 mmondor Exp $ */
 
 /*
  * Copyright (C) 2000-2004, Matthew Mondor
@@ -61,7 +61,7 @@ struct mmsql_threadsupport {
     void (*mutex_lock)(void *);
     void (*mutex_unlock)(void *);
     void (*thread_yield)(void);
-    void (*thread_sleep)(int);
+    unsigned int (*thread_sleep)(unsigned int);
 };
 
 
index 61bd582..1dc7523 100644 (file)
@@ -1,4 +1,20 @@
-$Id: ChangeLog,v 1.51 2005/03/05 15:37:48 mmondor Exp $
+$Id: ChangeLog,v 1.51.2.1 2005/11/24 07:13:39 mmondor Exp $
+
+
+
+Release: mmmail 0.1.0 devl
+Date   :
+By     : Matthew Mondor
+
+* Performance enhancements
+  - Now uses pthread instead of pth, using the new pthread_utils library
+    for functionality which pth had but pthread lacks.  This allows to
+    execute less functions through dedicated processes (which also require
+    some send(2)/recv(2) overhead), because of the expected preemptive
+    nature of most pthread implementations.  It also allows better scaling
+    with SMP.
+  - Uses PTHREAD_MUTEX_INITIALIZER where possible instead of
+    pthread_mutex_init().
 
 
 
index 9ad6850..08b6d0d 100644 (file)
@@ -1,16 +1,15 @@
-# $Id: GNUmakefile,v 1.7 2005/01/23 14:47:34 mmondor Exp $
+# $Id: GNUmakefile,v 1.7.2.1 2005/11/24 07:13:39 mmondor Exp $
 
 MMLIBS := $(addprefix ../mmlib/,mmfd.o mmhash.o mmlimitrate.o mmsql.o \
-mmlog.o mmpool.o mmreadcfg.o mmserver.o mm_pth_pool.o mmstat.o mmstr.o \
-mmstring.o)
+mmlog.o mmpool.o mmreadcfg.o mmserver.o mmstat.o mmstr.o \
+mmstring.o) $(addprefix ../../tests/pthread_utils/,mm_pthread_msg.o \
+mm_pthread_poll.o mm_pthread_pool.o mm_pthread_sleep.o)
 
-PTH_CFLAGS := $(shell pth-config --cflags)
-PTH_LDFLAGS := $(shell pth-config --ldflags --libs)
 MYSQL_CFLAGS := $(shell mysql_config --cflags)
 MYSQL_LDFLAGS := $(shell mysql_config --libs)
 
-CFLAGS += $(PTH_CFLAGS) $(MYSQL_CFLAGS) -I. -I../mmlib
-LDFLAGS += $(PTH_LDFLAGS) $(MYSQL_LDFLAGS) -lc -lcrypt
+CFLAGS += $(MYSQL_CFLAGS) -I. -I../mmlib -I../../tests/pthread_utils
+LDFLAGS += $(MYSQL_LDFLAGS) -lc -lcrypt -lpthread
 
 OBJS := src/mmsmtpd/mmsmtpd.o src/mmpop3d/mmpop3d.o src/mmrelayd/mmrelayd.o
 BINS := src/mmsmtpd/mmsmtpd src/mmpop3d/mmpop3d src/mmrelayd/mmrelayd
@@ -18,6 +17,8 @@ BINS := src/mmsmtpd/mmsmtpd src/mmpop3d/mmpop3d src/mmrelayd/mmrelayd
 CFLAGS += -Wall
 #CFLAGS += -DMMMAIL_MYSQL
 CFLAGS += -DMMMAIL_FILE
+#CFLAGS += -DNODETACH -DDEBUG -DPTHREAD_DEBUG
+#LDFLAGS += -lpthread_dbg
 
 
 all: $(BINS)
index ab1de52..7706195 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mmpop3d.c,v 1.40 2005/03/05 15:33:33 mmondor Exp $ */
+/* $Id: mmpop3d.c,v 1.40.2.1 2005/11/24 07:13:39 mmondor Exp $ */
 
 /*
  * Copyright (C) 2001-2004, Matthew Mondor
@@ -59,7 +59,8 @@
 #include <time.h>
 
 #include <ctype.h>
-#include <pth.h>
+
+#include <pthread.h>
 
 #include <mmtypes.h>
 #include <mmreadcfg.h>
@@ -74,6 +75,8 @@
 #include <mmstring.h>
 #include <mmstat.h>
 
+#include <mm_pthread_sleep.h>
+
 #include "mmpop3d.h"
 
 
@@ -81,7 +84,7 @@
 
 MMCOPYRIGHT("@(#) Copyright (c) 2001-2004\n\
 \tMatthew Mondor. All rights reserved.\n");
-MMRCSID("$Id: mmpop3d.c,v 1.40 2005/03/05 15:33:33 mmondor Exp $");
+MMRCSID("$Id: mmpop3d.c,v 1.40.2.1 2005/11/24 07:13:39 mmondor Exp $");
 
 
 
@@ -152,11 +155,11 @@ static const struct state states[] = {
 static int LOGLEVEL;
 
 /* Pool used to allocate clientenv nodes */
-static pth_mutex_t clenv_lock;
+static pthread_mutex_t clenv_lock = PTHREAD_MUTEX_INITIALIZER;
 static pool_t clenv_pool;
 
 /* Pool used to optimize creating/destroying mmfd mutexes */
-static pth_mutex_t mutexes_lock;
+static pthread_mutex_t mutexes_lock = PTHREAD_MUTEX_INITIALIZER;
 static pool_t mutexes_pool;
 
 /* Used for fast command lookup */
@@ -170,17 +173,17 @@ static fdbcontext fdbc;
 static fdfuncs gfdf = {
     malloc,
     free,
-    pth_poll,
-    pth_read,
-    pth_write,
-    pth_sleep,
-    pth_usleep,
-    _pth_mutex_create,
-    _pth_mutex_destroy,
-    _pth_mutex_lock,
-    _pth_mutex_unlock,
-    _pth_thread_yield,
-    _pth_eintr
+    poll,
+    read,
+    write,
+    pthread_sleep,
+    pthread_usleep,
+    thread_mutex_create,
+    thread_mutex_destroy,
+    thread_mutex_lock,
+    thread_mutex_unlock,
+    NULL,
+    thread_eintr
 };
 
 
@@ -255,12 +258,12 @@ main(int argc, char **argv)
        {NULL, 0}
     };
     struct mmsql_threadsupport mmsqlfuncs = {
-       _pth_mutex_create,
-       _pth_mutex_destroy, 
-       _pth_mutex_lock,
-       _pth_mutex_unlock,
-       _pth_thread_yield,
-       _pth_thread_sleep
+       thread_mutex_create,
+       thread_mutex_destroy, 
+       thread_mutex_lock,
+       thread_mutex_unlock,
+       NULL,
+       pthread_sleep
     };
     mmstat_t vstat;
 
@@ -380,10 +383,7 @@ main(int argc, char **argv)
     async_init(afuncs, CONF.ASYNC_PROCESSES, uid, gids, ngids);
 
     /* Things which shouldn't be part of the async pool processes */
-    pth_init();
-    async_init_pth();
-    pth_mutex_init(&clenv_lock);
-    pth_mutex_init(&mutexes_lock);
+    async_init_pthread();
 
     /* Allocate necessary pools */
     /* Client nodes */
@@ -886,9 +886,9 @@ alloc_clientenv(void)
 {
     clientenv *clenv;
 
-    pth_mutex_acquire(&clenv_lock, FALSE, NULL);
+    pthread_mutex_lock(&clenv_lock);
     clenv = (clientenv *)pool_alloc(&clenv_pool, TRUE);
-    pth_mutex_release(&clenv_lock);
+    pthread_mutex_unlock(&clenv_lock);
 
     if (clenv != NULL) {
        mmstat_init(&clenv->pstat, TRUE, FALSE);
@@ -939,9 +939,9 @@ free_clientenv(clientenv *clenv)
     if (clenv->index != NULL)
        free(clenv->index);
 
-    pth_mutex_acquire(&clenv_lock, FALSE, NULL);
+    pthread_mutex_lock(&clenv_lock);
     pool_free((pnode_t *)clenv);
-    pth_mutex_release(&clenv_lock);
+    pthread_mutex_unlock(&clenv_lock);
 
     return (NULL);
 }
@@ -1748,69 +1748,55 @@ handleclient(unsigned long id, int fd, clientlistnode *clientlnode,
 
 
 static void *
-_pth_mutex_create(void)
+thread_mutex_create(void)
 {
     struct mutexnode *mnod;
 
-    pth_mutex_acquire(&mutexes_lock, FALSE, NULL);
+    pthread_mutex_lock(&mutexes_lock);
     mnod = (struct mutexnode *)pool_alloc(&mutexes_pool, FALSE);
-    pth_mutex_release(&mutexes_lock);
+    pthread_mutex_unlock(&mutexes_lock);
 
     if (mnod != NULL)
-       pth_mutex_init(&mnod->mutex);
+       pthread_mutex_init(&mnod->mutex, NULL);
 
     return ((void *)mnod);
 }
 
 
 static void *
-_pth_mutex_destroy(void *mtx)
+thread_mutex_destroy(void *mtx)
 {
-    /* struct mutexnode *mnod = mtx; */
+    struct mutexnode *mnod = mtx;
 
-    /* pth_mutex_destroy(&mnod->mutex); */
-    pth_mutex_acquire(&mutexes_lock, FALSE, NULL);
+    pthread_mutex_destroy(&mnod->mutex);
+    pthread_mutex_lock(&mutexes_lock);
     pool_free(mtx);
-    pth_mutex_release(&mutexes_lock);
+    pthread_mutex_unlock(&mutexes_lock);
 
     return (NULL);
 }
 
 
 static void
-_pth_mutex_lock(void *mtx)
+thread_mutex_lock(void *mtx)
 {
     struct mutexnode *mnod = mtx;
 
-    pth_mutex_acquire(&mnod->mutex, FALSE, NULL);
+    pthread_mutex_lock(&mnod->mutex);
 }
 
 
 static void
-_pth_mutex_unlock(void *mtx)
+thread_mutex_unlock(void *mtx)
 {
     struct mutexnode *mnod = mtx;
 
-    pth_mutex_release(&mnod->mutex);
-}
-
-
-static void
-_pth_thread_yield(void)
-{
-    pth_yield(NULL);
-}
-
-
-static void
-_pth_thread_sleep(int secs)
-{
-    pth_sleep(secs);
+    pthread_mutex_unlock(&mnod->mutex);
 }
 
 
 static bool
-_pth_eintr(void)
+thread_eintr(void)
 {
     if (errno == EINTR)
        return TRUE;
index 7b5d296..67ba1e5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mmpop3d.h,v 1.16 2005/03/05 15:33:34 mmondor Exp $ */
+/* $Id: mmpop3d.h,v 1.16.2.1 2005/11/24 07:13:39 mmondor Exp $ */
 
 /*
  * Copyright (C) 2001-2004, Matthew Mondor
@@ -44,7 +44,7 @@
 
 #include <sys/types.h>
 
-#include <pth.h>
+#include <pthread.h>
 
 #include <mmtypes.h>
 #include <mmhash.h>
@@ -54,6 +54,8 @@
 #include <mmfd.h>
 #include <mmstat.h>
 
+#include <mm_pthread_sleep.h>
+
 
 
 
@@ -76,7 +78,7 @@
 #define REGISTER_ERROR(x) do { \
     (x)->errors++; \
        if (CONF.DELAY_ON_ERROR) \
-           pth_sleep((x)->errors); \
+           pthread_sleep((x)->errors); \
 } while(0)
 
 
@@ -143,7 +145,7 @@ typedef struct clientenv {
 /* Used for mmfd thread support delegation/abstraction */
 struct mutexnode {
     pnode_t node;
-    pth_mutex_t mutex;
+    pthread_mutex_t mutex;
 };
 
 /* This defines a state */
@@ -225,13 +227,11 @@ inline static bool valid_char(char);
 static int handleclient(unsigned long, int, clientlistnode *, struct iface *,
        struct async_clenv *);
 
-static void *_pth_mutex_create(void);
-static void *_pth_mutex_destroy(void *);
-static void _pth_mutex_lock(void *);
-static void _pth_mutex_unlock(void *);
-static void _pth_thread_yield(void);
-static void _pth_thread_sleep(int);
-static bool _pth_eintr(void);
+static void *thread_mutex_create(void);
+static void *thread_mutex_destroy(void *);
+static void thread_mutex_lock(void *);
+static void thread_mutex_unlock(void *);
+static bool thread_eintr(void);
 
 static void async_checkpw(struct async_msg *);
 static bool checkpw(clientenv *, const char *, const char *);
index 1001b2e..e3ce60d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mmsmtpd.c,v 1.74 2005/06/27 17:54:52 mmondor Exp $ */
+/* $Id: mmsmtpd.c,v 1.74.2.1 2005/11/24 07:13:39 mmondor Exp $ */
 
 /*
  * Copyright (C) 2001-2004, Matthew Mondor
 
 #include <syslog.h>
 
-#include <pth.h>
 #include <signal.h>
 #include <time.h>
 #include <dirent.h>
 
 #include <ctype.h>
 
+#include <pthread.h>
+
 #include <mmtypes.h>
 #include <mmreadcfg.h>
 #include <mmfd.h>
@@ -82,7 +83,7 @@
 
 MMCOPYRIGHT("@(#) Copyright (c) 2001-2004\n\
 \tMatthew Mondor. All rights reserved.\n");
-MMRCSID("$Id: mmsmtpd.c,v 1.74 2005/06/27 17:54:52 mmondor Exp $");
+MMRCSID("$Id: mmsmtpd.c,v 1.74.2.1 2005/11/24 07:13:39 mmondor Exp $");
 
 
 
@@ -131,19 +132,19 @@ static int LOGLEVEL;
 
 /* Used for clenv allocation buffering */
 static pool_t clenv_pool;
-static pth_mutex_t clenv_lock;
+static pthread_mutex_t clenv_lock = PTHREAD_MUTEX_INITIALIZER;
 
 /* Used for the flood protection cache */
 static pool_t hosts_pool;
 static hashtable_t hosts_table;
-static pth_mutex_t hosts_lock;
+static pthread_mutex_t hosts_lock = PTHREAD_MUTEX_INITIALIZER;
 
 /* Used for rcpt allocation buffering */
 static pool_t rcpt_pool;
-static pth_mutex_t rcpt_lock;
+static pthread_mutex_t rcpt_lock = PTHREAD_MUTEX_INITIALIZER;
 
 /* Pool used to optimize creating/destroying mmfd mutexes */
-static pth_mutex_t mutexes_lock;
+static pthread_mutex_t mutexes_lock = PTHREAD_MUTEX_INITIALIZER;
 static pool_t mutexes_pool;
 
 /* For fast command lookup */
@@ -181,17 +182,17 @@ static const struct reply_messages data_msg[DATA_MAX] = {
 static fdfuncs gfdf = {
     malloc,
     free,
-    pth_poll,
-    pth_read,
-    pth_write,
-    pth_sleep,
-    pth_usleep,
-    _pth_mutex_create,
-    _pth_mutex_destroy,
-    _pth_mutex_lock,
-    _pth_mutex_unlock,
-    _pth_thread_yield,
-    _pth_eintr
+    poll,
+    read,
+    write,
+    pthread_sleep,
+    pthread_usleep,
+    thread_mutex_create,
+    thread_mutex_destroy,
+    thread_mutex_lock,
+    thread_mutex_unlock,
+    NULL,
+    thread_eintr
 };
 
 /*
@@ -241,7 +242,7 @@ static const unsigned char valid_addr_host_table[256] = {
  * Connection to mmrelayd(8) establishment
  */
 int            relayd_sock = -1;
-pth_mutex_t    relayd_lock = PTH_MUTEX_INIT;
+pthread_mutex_t        relayd_lock = PTHREAD_MUTEX_INITIALIZER;
 
 
 
@@ -339,17 +340,17 @@ main(int argc, char **argv)
        {NULL, 0}
     };
     struct mmsql_threadsupport mmsqlfuncs = {
-       _pth_mutex_create,
-       _pth_mutex_destroy,
-       _pth_mutex_lock,
-       _pth_mutex_unlock,
-       _pth_thread_yield,
-       _pth_thread_sleep
+       thread_mutex_create,
+       thread_mutex_destroy,
+       thread_mutex_lock,
+       thread_mutex_unlock,
+       NULL,
+       pthread_sleep
     };
     mmstat_t vstat;
-    pth_t hosts_table_thread = NULL;
-    pth_t mmmail_db_gc_thread = NULL;
-    pth_attr_t threadattr;
+    pthread_t hosts_table_thread = NULL;
+    pthread_t mmmail_db_gc_thread = NULL;
+    pthread_attr_t threadattr;
 
     /* Set defaults */
     *CONF.CHROOT_DIR = 0;
@@ -506,12 +507,7 @@ main(int argc, char **argv)
     async_init(afuncs, CONF.ASYNC_PROCESSES, uid, gids, ngids);
 
     /* Things which shouldn't be part of the async pool processes */
-    pth_init();
-    async_init_pth();
-    pth_mutex_init(&clenv_lock);
-    pth_mutex_init(&hosts_lock);
-    pth_mutex_init(&rcpt_lock);
-    pth_mutex_init(&mutexes_lock);
+    async_init_pthread();
 
     /* Allocate necessary pools */
     /* Client nodes */
@@ -526,20 +522,21 @@ main(int argc, char **argv)
     pool_init(&mutexes_pool, "mutexes_pool", malloc, free, NULL, NULL,
            sizeof(struct mutexnode),
            (16384 * CONF.ALLOC_BUFFERS) / sizeof(struct mutexnode), 0, 0);
+
+    pthread_attr_init(&threadattr);
+    pthread_attr_setdetachstate(&threadattr, 0);
+
     /* Rate nodes */
     if (CONF.FLOOD_PROTECTION) {
        pool_init(&hosts_pool, "hosts_pool", malloc, free, NULL, NULL,
                sizeof(hostnode), CONF.FLOOD_CACHE, 1, 1);
        hashtable_init(&hosts_table, "hosts_table", CONF.FLOOD_CACHE, 1,
                malloc, free, mm_memcmp, mm_memhash32, FALSE);
-       threadattr = pth_attr_new();
-       pth_attr_set(threadattr, PTH_ATTR_JOINABLE, TRUE);
-       hosts_table_thread = pth_spawn(threadattr, hosts_expire_thread, NULL);
+       pthread_create(&hosts_table_thread, &threadattr, hosts_expire_thread,
+                      NULL);
     }
     /* Launch box directories cleaning thread */
-    threadattr = pth_attr_new();
-    pth_attr_set(threadattr, PTH_ATTR_JOINABLE, TRUE);
-    mmmail_db_gc_thread = pth_spawn(threadattr, db_gc_thread, NULL);
+    pthread_create(&mmmail_db_gc_thread, &threadattr, db_gc_thread, NULL);
     /* mmstr nodes */
     strlist = mmstrinit(malloc, free, 65536 * CONF.ALLOC_BUFFERS);
 
@@ -569,6 +566,7 @@ main(int argc, char **argv)
 
     if (strlist)
        mmstrexit();
+    /* XXX
     if (hosts_table_thread != NULL) {
        pth_abort(hosts_table_thread);
        pth_join(hosts_table_thread, NULL);
@@ -577,6 +575,7 @@ main(int argc, char **argv)
        pth_abort(mmmail_db_gc_thread);
        pth_join(mmmail_db_gc_thread, NULL);
     }
+    */
     if (HASHTABLE_VALID(&command_table))
        hashtable_destroy(&command_table, FALSE);
     if (POOL_VALID(&command_pool))
@@ -912,20 +911,13 @@ all_rcpt(clientenv *clenv)
      */
     {
        register rcptnode *rnode;
-       register int cnt;
 
        ahash = mm_strhash64(addr);
-       cnt = 0;
        DLIST_FOREACH(&clenv->rcpt, rnode) {
            if (rnode->hash == ahash) {
                reason = RCPT_EXISTS;
                goto end;
            }
-           cnt++;
-           if (cnt > 64) {
-               cnt = 0;
-               pth_yield(NULL);
-           }
        }
     }
 
@@ -944,7 +936,7 @@ all_rcpt(clientenv *clenv)
        len = mm_strlen(entry);
 
        valid = TRUE;
-       pth_mutex_acquire(&hosts_lock, FALSE, NULL);
+       pthread_mutex_lock(&hosts_lock);
        /* First acquire our hostnode, or create it if required */
        if ((hnod = (hostnode *)hashtable_lookup(&hosts_table, entry, len + 1))
                == NULL) {
@@ -972,7 +964,7 @@ all_rcpt(clientenv *clenv)
                        clenv->id, LR_POSTS(&hnod->lr), CONF.FLOOD_EXPIRES);
            }
        }
-       pth_mutex_release(&hosts_lock);
+       pthread_mutex_unlock(&hosts_lock);
 
        if (!valid) {
            if (CONF.STATFAIL_FLOOD)
@@ -988,9 +980,9 @@ all_rcpt(clientenv *clenv)
        register rcptnode *rnode;
 
        reason = RCPT_ERROR;
-       pth_mutex_acquire(&rcpt_lock, FALSE, NULL);
+       pthread_mutex_lock(&rcpt_lock);
        rnode = (rcptnode *)pool_alloc(&rcpt_pool, FALSE);
-       pth_mutex_release(&rcpt_lock);
+       pthread_mutex_unlock(&rcpt_lock);
        if (rnode != NULL) {
            mm_strcpy(rnode->address, (relay ? foraddr : addr));
            mm_strcpy(rnode->foraddress, foraddr);
@@ -1151,9 +1143,9 @@ alloc_clientenv(void)
 {
     clientenv *clenv;
 
-    pth_mutex_acquire(&clenv_lock, FALSE, NULL);
+    pthread_mutex_lock(&clenv_lock);
     clenv = (clientenv *)pool_alloc(&clenv_pool, TRUE);
-    pth_mutex_release(&clenv_lock);
+    pthread_mutex_unlock(&clenv_lock);
 
     if (clenv != NULL) {
        mmstat_init(&clenv->vstat, TRUE, TRUE);
@@ -1190,9 +1182,9 @@ free_clientenv(clientenv *clenv)
        mmstrfree(clenv->from);
     empty_rcpts(&clenv->rcpt);
 
-    pth_mutex_acquire(&clenv_lock, FALSE, NULL);
+    pthread_mutex_lock(&clenv_lock);
     pool_free((pnode_t *)clenv);
-    pth_mutex_release(&clenv_lock);
+    pthread_mutex_unlock(&clenv_lock);
 
     return (NULL);
 }
@@ -1206,7 +1198,7 @@ empty_rcpts(list_t *lst)
 {
     node_t *nod, *tmp;
 
-    pth_mutex_acquire(&rcpt_lock, FALSE, NULL);
+    pthread_mutex_lock(&rcpt_lock);
 
     for (nod = DLIST_TOP(lst); nod != NULL; nod = tmp) {
        tmp = DLIST_NEXT(nod);
@@ -1214,7 +1206,7 @@ empty_rcpts(list_t *lst)
     }
     DLIST_INIT(lst);
 
-    pth_mutex_release(&rcpt_lock);
+    pthread_mutex_unlock(&rcpt_lock);
 }
 
 
@@ -1246,7 +1238,7 @@ check_alias(char *addr)
     if ((mysqlres = mmsql_query(query, mm_strlen(query))) != NULL) {
        if ((mysql_num_rows(mysqlres)) > 0) {
            char pat[64];
-           int cur = 0, max = -1, cnt = 0;
+           int cur = 0, max = -1;
            MYSQL_ROW *row;
            unsigned long *lengths;
 
@@ -1266,11 +1258,6 @@ check_alias(char *addr)
                        }
                    }
                }
-               cnt++;
-               if (cnt > 64) {
-                   cnt = 0;
-                   pth_yield(NULL);
-               }
            }
            if (max > -1)
                res = TRUE;
@@ -1297,7 +1284,6 @@ check_nofrom(const char *addr, const char *host)
     if ((mysqlres = mmsql_query("SELECT nofrom_pattern FROM nofrom", -1))
            != NULL) {
        if ((mysql_num_rows(mysqlres)) > 0) {
-           int cnt = 0;
            MYSQL_ROW *row;
            unsigned long *lengths;
 
@@ -1321,11 +1307,6 @@ check_nofrom(const char *addr, const char *host)
                        }
                    }
                }
-               cnt++;
-               if (cnt > 64) {
-                   cnt = 0;
-                   pth_yield(NULL);
-               }
            }
        }
        mysqlres = mmsql_free_result(mysqlres);
@@ -2418,7 +2399,7 @@ do_data_queue_notify(clientenv *clenv)
      * If we cannot obtain lock, we know that it's already being notified, and
      * we don't need to do anything.
      */
-    if (pth_mutex_acquire(&relayd_lock, TRUE, NULL) == FALSE)
+    if (pthread_mutex_lock(&relayd_lock) != 0)
        return;
 
     /*
@@ -2435,7 +2416,7 @@ do_data_queue_notify(clientenv *clenv)
      * and send it again, but once only.
      */
     for (;;) {
-       if (pth_write(relayd_sock, "N", 1) != 1) {
+       if (write(relayd_sock, "N", 1) != 1) {
            (void) close(relayd_sock);
            if ((relayd_sock = do_data_queue_notify_connect()) != -1)
                continue;
@@ -2450,7 +2431,7 @@ end:
        mmsyslog(0, LOGLEVEL,
                "mmrelayd(8) could not be notified (not running?)");
 
-    (void) pth_mutex_release(&relayd_lock);
+    (void) pthread_mutex_unlock(&relayd_lock);
 }
 
 /*
@@ -2472,7 +2453,7 @@ do_data_queue_notify_connect(void)
        mm_memclr(&addr, sizeof(struct sockaddr_un));
        (void) mm_strncpy(addr.sun_path, CONF.MMRELAYD_SOCKET_PATH, 100);
        addr.sun_family = AF_UNIX;
-       if ((pth_connect(fd, (struct sockaddr *)&addr,
+       if ((connect(fd, (struct sockaddr *)&addr,
                        sizeof(struct sockaddr_un))) == -1) {
            (void) close(fd);
            fd = -1;
@@ -2678,69 +2659,55 @@ handleclient(unsigned long id, int fd, clientlistnode *clientlnode,
 
 
 static void *
-_pth_mutex_create(void)
+thread_mutex_create(void)
 {
     struct mutexnode *mnod;
 
-    pth_mutex_acquire(&mutexes_lock, FALSE, NULL);
+    pthread_mutex_lock(&mutexes_lock);
     mnod = (struct mutexnode *)pool_alloc(&mutexes_pool, FALSE);
-    pth_mutex_release(&mutexes_lock);
+    pthread_mutex_unlock(&mutexes_lock);
 
     if (mnod != NULL)
-       pth_mutex_init(&mnod->mutex);
+       pthread_mutex_init(&mnod->mutex, NULL);
 
     return ((void *)mnod);
 }
 
 
 static void *
-_pth_mutex_destroy(void *mtx)
+thread_mutex_destroy(void *mtx)
 {
-    /* struct mutexnode *mnod = mtx; */
+    struct mutexnode *mnod = mtx;
 
-    /* pth_mutex_destroy(&mnod->mutex); */
-    pth_mutex_acquire(&mutexes_lock, FALSE, NULL);
+    pthread_mutex_destroy(&mnod->mutex);
+    pthread_mutex_lock(&mutexes_lock);
     pool_free(mtx);
-    pth_mutex_release(&mutexes_lock);
+    pthread_mutex_unlock(&mutexes_lock);
 
     return (NULL);
 }
 
 
 static void
-_pth_mutex_lock(void *mtx)
+thread_mutex_lock(void *mtx)
 {
     struct mutexnode *mnod = mtx;
 
-    pth_mutex_acquire(&mnod->mutex, FALSE, NULL);
+    pthread_mutex_lock(&mnod->mutex);
 }
 
 
 static void
-_pth_mutex_unlock(void *mtx)
+thread_mutex_unlock(void *mtx)
 {
     struct mutexnode *mnod = mtx;
 
-    pth_mutex_release(&mnod->mutex);
-}
-
-
-static void
-_pth_thread_yield(void)
-{
-    pth_yield(NULL);
-}
-
-
-static void
-_pth_thread_sleep(int secs)
-{
-    pth_sleep(secs);
+    pthread_mutex_unlock(&mnod->mutex);
 }
 
 
 static bool
-_pth_eintr(void)
+thread_eintr(void)
 {
     if (errno == EINTR)
        return TRUE;
@@ -2799,10 +2766,9 @@ hosts_expire_thread(void *args)
 
     /* Set the initial timeout to the maximum allowed */
     data.soonest = CONF.FLOOD_EXPIRES * 60;
-    data.cnt = 0;
     for (;;) {
        /* Sleep until it is known that at least one node expired */
-       pth_sleep((unsigned int)data.soonest);
+       pthread_sleep(data.soonest);
        /* Tell our iterator function the current time and the maximum
         * allowed time to wait to
         */
@@ -2811,15 +2777,15 @@ hosts_expire_thread(void *args)
        /* Lock hosts_table, expunge expired nodes and set data.soonest to the
         * time of the soonest next expireing node
         */
-       pth_mutex_acquire(&hosts_lock, FALSE, NULL);
+       pthread_mutex_lock(&hosts_lock);
        if (HASHTABLE_NODES(&hosts_table) > 0)
            hashtable_iterate(&hosts_table, hosts_expire_thread_iterator,
                    &data);
-       pth_mutex_release(&hosts_lock);
+       pthread_mutex_unlock(&hosts_lock);
     }
 
     /* NOTREACHED */
-    pth_exit(NULL);
+    pthread_exit(NULL);
     return NULL;
 }
 
@@ -2842,12 +2808,6 @@ hosts_expire_thread_iterator(hashnode_t *hnod, void *udata)
            data->soonest = rem;
     }
 
-    /* If the cache is big, prevent from interfering with other threads */
-    if ((data->cnt++) == 64) {
-       data->cnt = 0;
-       pth_yield(NULL);
-    }
-
     return TRUE;
 }
 
@@ -2869,7 +2829,7 @@ db_gc_thread(void *args)
     for (rounds = 1; ; rounds++) {
        MYSQL_RES       *mysqlres;
 
-       (void) pth_sleep(60);
+       (void) pthread_sleep(60);
 
        /*
         * Perform dangling mailbox directories cleanup
@@ -2959,7 +2919,7 @@ db_gc_thread(void *args)
     }
 
     /* NOTREACHED */
-    pth_exit(NULL);
+    pthread_exit(NULL);
     return NULL;
 }
 
@@ -2969,7 +2929,6 @@ db_gc_thread_delete(const char *addr)
     char               dirpath[256], filepath[256];
     DIR                        *dir;
     struct dirent      ent, *res;
-    int                        count;
 
     /*
      * Now <path> holds the actual directory to delete mail from. We know
@@ -2982,16 +2941,11 @@ db_gc_thread_delete(const char *addr)
        return;
     }
 
-    count = 1;
     while (readdir_r(dir, &ent, &res) == 0 && res == &ent) {
        (void) snprintf(filepath, 255, "%s/%s", dirpath, ent.d_name);
        if (unlink(filepath) != 0)
            syslog(LOG_NOTICE, "db_gc_thread_delete(%s) - unlink(%s) == %s",
                    addr, filepath, strerror(errno));
-       if (++count == 64) {
-           count = 0;
-           (void) pth_yield(NULL);
-       }
     }
     if (rmdir(dirpath) != 0)
        syslog(LOG_NOTICE, "db_gc_thread_delete(%s) - rmdir(%s) == %s",
index 9cb9a01..6c5b747 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mmsmtpd.h,v 1.33 2005/03/26 11:45:48 mmondor Exp $ */
+/* $Id: mmsmtpd.h,v 1.33.2.1 2005/11/24 07:13:39 mmondor Exp $ */
 
 /*
  * Copyright (C) 2001-2004, Matthew Mondor
@@ -45,7 +45,8 @@
 #include <sys/types.h>
 #include <time.h>
 
-#include <pth.h>
+#include <pthread.h>
+#include <mm_pthread_sleep.h>
 
 #include <mmtypes.h>
 #include <mmlist.h>
@@ -110,7 +111,7 @@ enum data_reason {
 #define REGISTER_ERROR(x)      do { \
     (x)->errors++; \
        if (CONF.DELAY_ON_ERROR) \
-           pth_sleep((x)->errors); \
+           pthread_sleep((x)->errors); \
 } while(FALSE)
 
 /* Evaluates if a character is valid for addresses and hostnames */
@@ -182,13 +183,12 @@ typedef struct hostnode {
 
 struct hosts_expire_thread_iterator_udata {
     time_t current, soonest;
-    int cnt;
 };
 
 /* Used for mmfd thread support delegation/abstraction */
 struct mutexnode {
     pnode_t node;
-    pth_mutex_t mutex;
+    pthread_mutex_t mutex;
 };
 
 /* This defines a state */
@@ -317,13 +317,11 @@ static int do_data_queue_notify_connect(void);
 static int handleclient(unsigned long, int, clientlistnode *, struct iface *,
        struct async_clenv *);
 
-static void *_pth_mutex_create(void);
-static void *_pth_mutex_destroy(void *);
-static void _pth_mutex_lock(void *);
-static void _pth_mutex_unlock(void *);
-static void _pth_thread_yield(void);
-static void _pth_thread_sleep(int);
-static bool _pth_eintr(void);
+static void *thread_mutex_create(void);
+static void *thread_mutex_destroy(void *);
+static void thread_mutex_lock(void *);
+static void thread_mutex_unlock(void *);
+static bool thread_eintr(void);
 
 static void async_resquery(struct async_msg *);
 static int a_res_query(clientenv *, const char *, int, int, u_char *, int);