You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tcl.apache.org by mx...@apache.org on 2019/01/21 21:10:35 UTC

[tcl-rivet] 01/05: Add experimental thread_id command

This is an automated email from the ASF dual-hosted git repository.

mxmanghi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tcl-rivet.git

commit b953d0dda77cf074c32676dc29f91a388ab3a64b
Author: Massimo Manghi <mx...@apache.org>
AuthorDate: Tue Jan 15 01:03:03 2019 +0100

    Add experimental thread_id command
---
 src/mod_rivet_ng/rivetCore.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/mod_rivet_ng/rivetCore.c b/src/mod_rivet_ng/rivetCore.c
index 66cb9d8..969569c 100644
--- a/src/mod_rivet_ng/rivetCore.c
+++ b/src/mod_rivet_ng/rivetCore.c
@@ -43,7 +43,7 @@
 #include <stdio.h>
 #include <apr_errno.h>
 #include <apr_strings.h>
-
+#include <apr_portable.h>
 
 #include "apache_request.h"
 #include "mod_rivet.h"
@@ -1932,6 +1932,36 @@ TCL_CMD_HEADER( Rivet_UrlScript )
 
 /*
  *-----------------------------------------------------------------------------
+ * Rivet_GetThreadId --
+ *
+ *
+ */
+
+#define SMALL_BUFFER_SIZE 32
+
+TCL_CMD_HEADER( Rivet_GetThreadId )
+{
+    rivet_thread_private*   private;
+    char                    buff[SMALL_BUFFER_SIZE];
+    apr_os_thread_t         threadid;
+    Tcl_Obj*                result_obj;
+    rivet_thread_interp*    interp_obj;
+
+    threadid = apr_os_thread_current();
+
+    THREAD_PRIVATE_DATA(private)
+
+    interp_obj = RIVET_PEEK_INTERP(private,private->running_conf);
+
+    threadid = apr_os_thread_current();
+    snprintf(buff,SMALL_BUFFER_SIZE,"0x%8.8lx",threadid);
+    result_obj = Tcl_NewStringObj(buff,strlen(buff));
+
+    Tcl_SetObjResult(interp_obj->interp,result_obj);
+    return TCL_OK;
+}
+/*
+ *-----------------------------------------------------------------------------
  *
  * Rivet_InitCore --
  *
@@ -1972,6 +2002,7 @@ Rivet_InitCore(Tcl_Interp *interp,rivet_thread_private* private)
     RIVET_OBJ_CMD ("inspect",Rivet_InspectCmd,private);
     RIVET_OBJ_CMD ("exit",Rivet_ExitCmd,private);
     RIVET_OBJ_CMD ("url_script",Rivet_UrlScript,private);
+    RIVET_OBJ_CMD ("thread_id",Rivet_GetThreadId,private);
 
 #ifdef TESTPANIC
     RIVET_OBJ_CMD ("testpanic",TestpanicCmd,private);
@@ -2012,6 +2043,7 @@ Rivet_InitCore(Tcl_Interp *interp,rivet_thread_private* private)
         RIVET_EXPORT_CMD(interp,rivet_ns,"env");
         RIVET_EXPORT_CMD(interp,rivet_ns,"apache_log_error");
         RIVET_EXPORT_CMD(interp,rivet_ns,"inspect");
+        RIVET_EXPORT_CMD(interp,rivet_ns,"thread_id");
         // ::rivet::exit is not exported
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tcl.apache.org
For additional commands, e-mail: commits-help@tcl.apache.org