gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r13930 - in libmicrohttpd: . doc src/daemon src/include


From: gnunet
Subject: [GNUnet-SVN] r13930 - in libmicrohttpd: . doc src/daemon src/include
Date: Sun, 19 Dec 2010 13:47:23 +0100

Author: grothoff
Date: 2010-12-19 13:47:23 +0100 (Sun, 19 Dec 2010)
New Revision: 13930

Modified:
   libmicrohttpd/ChangeLog
   libmicrohttpd/doc/microhttpd.texi
   libmicrohttpd/src/daemon/daemon.c
   libmicrohttpd/src/daemon/internal.h
   libmicrohttpd/src/include/microhttpd.h
Log:
option to set stack size

Modified: libmicrohttpd/ChangeLog
===================================================================
--- libmicrohttpd/ChangeLog     2010-12-19 12:46:24 UTC (rev 13929)
+++ libmicrohttpd/ChangeLog     2010-12-19 12:47:23 UTC (rev 13930)
@@ -1,3 +1,6 @@
+Sun Dec 19 13:46:52 CET 2010
+       Added option to specify size of stacks for threads created by MHD. -CG
+
 Tue Nov 23 09:41:00 CET 2010
        Releasing libmicrohttpd 0.9.3. -CG
 

Modified: libmicrohttpd/doc/microhttpd.texi
===================================================================
--- libmicrohttpd/doc/microhttpd.texi   2010-12-19 12:46:24 UTC (rev 13929)
+++ libmicrohttpd/doc/microhttpd.texi   2010-12-19 12:47:23 UTC (rev 13930)
@@ -562,6 +562,15 @@
 (the result must be shorter than the input and still be 0-terminated).
 @code{cls} will be set to the second argument following
 MHD_OPTION_UNESCAPE_CALLBACK.
+
+  
address@hidden MHD_OPTION_THREAD_STACK_SIZE
address@hidden stack, thread, pthread
+Maximum stack size for threads created by MHD.  This option must be
+followed by a @code{size_t}).  Not specifying this option or using
+a value of zero means using the system default (which is likely to 
+differ based on your platform).
+
 @end table
 @end deftp
 

Modified: libmicrohttpd/src/daemon/daemon.c
===================================================================
--- libmicrohttpd/src/daemon/daemon.c   2010-12-19 12:46:24 UTC (rev 13929)
+++ libmicrohttpd/src/daemon/daemon.c   2010-12-19 12:47:23 UTC (rev 13930)
@@ -753,6 +753,52 @@
 
 
 /**
+ * Create a thread and set the attributes according to our options.
+ * 
+ * @param thread handle to initialize
+ * @param daemon daemon with options
+ * @param start_routine main function of thread
+ * @param arg argument for start_routine
+ * @return 0 on success
+ */
+static int
+create_thread (pthread_t * thread,
+              const struct MHD_Daemon *daemon,
+              void *(*start_routine)(void*),
+              void *arg)
+{
+  pthread_attr_t attr;
+  pthread_attr_t *pattr;
+  int ret;
+  
+  if (daemon->thread_stack_size != 0) 
+    {
+      if ( (0 != (ret = pthread_attr_init (&attr))) ||
+          (0 != (ret = pthread_attr_setstacksize (&attr, 
daemon->thread_stack_size))) )
+       {
+#if HAVE_MESSAGES
+         MHD_DLOG (daemon,
+                   "Failed to set thread stack size\n");
+#endif
+         errno = EINVAL;
+         return ret;
+       }
+      pattr = &attr;
+    }
+  else
+    {
+      pattr = NULL;
+    }
+  ret = pthread_create (thread, pattr,
+                       start_routine, arg);
+  if (pattr != NULL)
+    pthread_attr_destroy (&attr);
+  return ret;
+}
+
+
+
+/**
  * Accept an incoming connection and create the MHD_Connection object for
  * it.  This function also enforces policy by way of checking with the
  * accept policy callback.
@@ -943,8 +989,8 @@
   /* attempt to create handler thread */
   if (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION))
     {
-      res_thread_create = pthread_create (&connection->pid, NULL,
-                                          &MHD_handle_connection, connection);
+      res_thread_create = create_thread (&connection->pid, daemon,
+                                        &MHD_handle_connection, connection);
       if (res_thread_create != 0)
         {
 #if HAVE_MESSAGES
@@ -1464,6 +1510,9 @@
           va_arg (ap, void *);
 #endif
           break;
+        case MHD_OPTION_THREAD_STACK_SIZE:
+          daemon->thread_stack_size = va_arg (ap, size_t);
+          break;
        case MHD_OPTION_ARRAY:
          oa = va_arg (ap, struct MHD_OptionItem*);
          i = 0;
@@ -1473,6 +1522,7 @@
                {
                  /* all options taking 'size_t' */
                case MHD_OPTION_CONNECTION_MEMORY_LIMIT:
+               case MHD_OPTION_THREAD_STACK_SIZE:
                  if (MHD_YES != parse_options (daemon,
                                                servaddr,
                                                opt,
@@ -1904,7 +1954,7 @@
         ( (0 != (options & MHD_USE_SELECT_INTERNALLY)) &&
           (0 == retVal->worker_pool_size)) ) && 
        (0 != (res_thread_create =
-             pthread_create (&retVal->pid, NULL, &MHD_select_thread, retVal))))
+             create_thread (&retVal->pid, retVal, &MHD_select_thread, 
retVal))))
     {
 #if HAVE_MESSAGES
       MHD_DLOG (retVal,
@@ -1982,7 +2032,7 @@
             ++d->max_connections;
 
           /* Spawn the worker thread */
-          if (0 != (res_thread_create = pthread_create (&d->pid, NULL, 
&MHD_select_thread, d)))
+          if (0 != (res_thread_create = create_thread (&d->pid, retVal, 
&MHD_select_thread, d)))
             {
 #if HAVE_MESSAGES
               MHD_DLOG (retVal,

Modified: libmicrohttpd/src/daemon/internal.h
===================================================================
--- libmicrohttpd/src/daemon/internal.h 2010-12-19 12:46:24 UTC (rev 13929)
+++ libmicrohttpd/src/daemon/internal.h 2010-12-19 12:47:23 UTC (rev 13930)
@@ -825,6 +825,11 @@
   size_t pool_size;
 
   /**
+   * Size of threads created by MHD.
+   */
+  size_t thread_stack_size;
+
+  /**
    * Number of worker daemons
    */
   unsigned int worker_pool_size;

Modified: libmicrohttpd/src/include/microhttpd.h
===================================================================
--- libmicrohttpd/src/include/microhttpd.h      2010-12-19 12:46:24 UTC (rev 
13929)
+++ libmicrohttpd/src/include/microhttpd.h      2010-12-19 12:47:23 UTC (rev 
13930)
@@ -558,7 +558,15 @@
    * the nonce counter. This option should be followed by a "unsigend int"
    * argument.
    */
-  MHD_OPTION_NONCE_NC_SIZE = 18
+  MHD_OPTION_NONCE_NC_SIZE = 18,
+
+  /**
+   * Desired size of the stack for threads created by MHD. Followed
+   * by an argument of type 'size_t'.  Use 0 for system 'default'.
+   */
+  MHD_OPTION_THREAD_STACK_SIZE = 19
+
+
 };
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]