Added silc_stack_[set|get]_global.
authorPekka Riikonen <priikone@silcnet.org>
Wed, 2 Jan 2008 20:37:24 +0000 (20:37 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Wed, 2 Jan 2008 20:37:24 +0000 (20:37 +0000)
CHANGES.RUNTIME
lib/silcutil/silcstack.c
lib/silcutil/silcstack.h

index 6901253d4a4fba772117b5c612850b7b4c9f5ebe..46b440d885e5dc74831497fd96938f462f6ab385 100644 (file)
@@ -1,3 +1,20 @@
+Wed Jan  2 22:39:57 EET 2008  Pekka Riikonen <priikone@silcnet.org>
+
+       * Added silc_stack_[set|get]_global to set/get global per-thread
+         SilcStack.  Affected files are lib/silcutil/silcstack.[ch].
+
+       * Imported new improved free regex implementation.  Added (again)
+         support for SILC_REGEX_NOTBOL and SILC_REGEX_NOTEOLF flags.
+         Added also support for POSIX bounded repeat expression (a{n,m}) 
+         to make it more POSIX compliant.  Added SilcStack support to
+         the regex too.  Affected files are lib/silcutil/silcregex.[ch].
+
+       * Added silc_buffer_printf to lib/silcutil/silcbuffer.h.
+
+       * Changed silc_srealloc to allocate new memory block if reallocation
+         from stack fails, and to copy the old data to the new one.
+         Affected files are lib/silcutil/silcmemory.[ch].
+
 Tue Jan  1 19:40:15 EET 2008  Pekka Riikonen <priikone@silcnet.org>
 
        * Added SILC_REGEX_NOTBOL and SILC_REGEX_NOTEOL flags to
index 79f63d2fc8552242223be51cadbccb5c69d7ff40..3fd06d331459680cefa66328ccdb735500c6f866 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2003 - 2007 Pekka Riikonen
+  Copyright (C) 2003 - 2008 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -603,6 +603,35 @@ SilcBool silc_stack_purge(SilcStack stack)
   return ret;
 }
 
+/* Set global stack */
+
+void silc_stack_set_global(SilcStack stack)
+{
+  SilcTls tls = silc_thread_get_tls();
+
+  if (!tls) {
+    /* Try to initialize Tls */
+    tls = silc_thread_tls_init();
+    SILC_VERIFY(tls);
+    if (!tls)
+      return;
+  }
+
+  tls->stack = stack;
+}
+
+/* Return global stack */
+
+SilcStack silc_stack_get_global(void)
+{
+  SilcTls tls = silc_thread_get_tls();
+
+  if (!tls)
+    return NULL;
+
+  return tls->stack;
+}
+
 #ifdef SILC_DIST_INPLACE
 /* Statistics dumping. */
 
index c4415a17c15978d385ebddeb8ba70cce903ae372..017a55d0b488fe461246e2fa32d9438d632ae49f 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2003 - 2007 Pekka Riikonen
+  Copyright (C) 2003 - 2008 Pekka Riikonen
 
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -384,6 +384,42 @@ SilcUInt32 silc_stack_get_alignment(SilcStack stack);
  ***/
 SilcBool silc_stack_purge(SilcStack stack);
 
+/****f* silcutil/SilcStackAPI/silc_stack_set_global
+ *
+ * SYNOPSIS
+ *
+ *    void silc_stack_set_global(SilcStack stack);
+ *
+ * DESCRIPTION
+ *
+ *    Sets global SilcStack `stack' that can be retrieved at any time
+ *    by using silc_stack_get_global.  The global stack is global only
+ *    to the current thread.  Each thread can have their own global stack.
+ *    If each thread must have own stack this must be called in each
+ *    thread.  If the global stack has been set already, new call will
+ *    replace the old one.
+ *
+ *    This routine is provided only as a convenience function to store
+ *    program's or thread's stack in one global place.  It is not mandatory
+ *    to call this function in order to use SilcStack.
+ *
+ ***/
+void silc_stack_set_global(SilcStack stack);
+
+/****f* silcutil/SilcStackAPI/silc_stack_get_global
+ *
+ * SYNOPSIS
+ *
+ *    SilcStack silc_stack_get_global(void);
+ *
+ * DESCRIPTION
+ *
+ *    Returns the thread's global stack that was set by calling the
+ *    silc_stack_set_global or NULL if global stack has not been set.
+ *
+ ***/
+SilcStack silc_stack_get_global(void);
+
 #include "silcstack_i.h"
 
 #endif /* SILCSTACK_H */