[58834] trunk/base/src/pextlib1.0

toby at macports.org toby at macports.org
Mon Oct 5 22:05:43 PDT 2009


Revision: 58834
          http://trac.macports.org/changeset/58834
Author:   toby at macports.org
Date:     2009-10-05 22:05:42 -0700 (Mon, 05 Oct 2009)
Log Message:
-----------
Avoid calling curl_global_init for actions that don't require it - this should be a noticeable performance gain.

Modified Paths:
--------------
    trunk/base/src/pextlib1.0/Pextlib.c
    trunk/base/src/pextlib1.0/curl.c
    trunk/base/src/pextlib1.0/curl.h

Modified: trunk/base/src/pextlib1.0/Pextlib.c
===================================================================
--- trunk/base/src/pextlib1.0/Pextlib.c	2009-10-06 05:03:58 UTC (rev 58833)
+++ trunk/base/src/pextlib1.0/Pextlib.c	2009-10-06 05:05:42 UTC (rev 58834)
@@ -623,8 +623,5 @@
 	if (Tcl_PkgProvide(interp, "Pextlib", "1.0") != TCL_OK)
 		return TCL_ERROR;
 
-	/* init libcurl */
-	CurlInit(interp);
-
 	return TCL_OK;
 }

Modified: trunk/base/src/pextlib1.0/curl.c
===================================================================
--- trunk/base/src/pextlib1.0/curl.c	2009-10-06 05:03:58 UTC (rev 58833)
+++ trunk/base/src/pextlib1.0/curl.c	2009-10-06 05:05:42 UTC (rev 58834)
@@ -36,6 +36,7 @@
 
 #include <ctype.h>
 #include <errno.h>
+#include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -71,6 +72,8 @@
 int CurlIsNewerCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]);
 int CurlGetSizeCmd(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]);
 
+void CurlInit(void);
+
 /* ========================================================================= **
  * Entry points
  * ========================================================================= */
@@ -821,7 +824,11 @@
 	};
 	int theResult = TCL_OK;
     EOption theOptionIndex;
+	static pthread_once_t once = PTHREAD_ONCE_INIT;
 
+	/* TODO: use dispatch_once when we drop Leopard support */
+	pthread_once(&once, CurlInit);
+
 	if (objc < 3) {
 		Tcl_WrongNumArgs(interp, 1, objv, "option ?arg ...?");
 		return TCL_ERROR;
@@ -857,11 +864,12 @@
 /**
  * curl init entry point.
  *
+ * libcurl will never be cleaned (where should I plug the hook?)
+ *
  * @param interp		current interpreter
  */
-int
-CurlInit(Tcl_Interp* interp)
+void
+CurlInit()
 {
-	CURLcode theCurlCode = curl_global_init(CURL_GLOBAL_ALL);
-	return SetResultFromCurlErrorCode(interp, theCurlCode);
+	curl_global_init(CURL_GLOBAL_ALL);
 }

Modified: trunk/base/src/pextlib1.0/curl.h
===================================================================
--- trunk/base/src/pextlib1.0/curl.h	2009-10-06 05:03:58 UTC (rev 58833)
+++ trunk/base/src/pextlib1.0/curl.h	2009-10-06 05:05:42 UTC (rev 58834)
@@ -36,12 +36,6 @@
 #include <tcl.h>
 
 /**
- * Init libcurl.
- * libcurl will never be cleaned (where should I plug the hook?)
- */
-int CurlInit(Tcl_Interp* interp);
-
-/**
  * A native command to use libcurl.
  *
  * The syntax is:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20091005/d9f24f20/attachment.html>


More information about the macports-changes mailing list