From: Pekka Riikonen Date: Wed, 2 Jan 2008 20:37:24 +0000 (+0000) Subject: Added silc_stack_[set|get]_global. X-Git-Tag: 1.2.beta1~41 X-Git-Url: http://git.silcnet.org/gitweb/?p=crypto.git;a=commitdiff_plain;h=eff4c7d3a6068f5feccd41d423824ff6180f4dc5 Added silc_stack_[set|get]_global. --- diff --git a/CHANGES.RUNTIME b/CHANGES.RUNTIME index 6901253d..46b440d8 100644 --- a/CHANGES.RUNTIME +++ b/CHANGES.RUNTIME @@ -1,3 +1,20 @@ +Wed Jan 2 22:39:57 EET 2008 Pekka Riikonen + + * 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 * Added SILC_REGEX_NOTBOL and SILC_REGEX_NOTEOL flags to diff --git a/lib/silcutil/silcstack.c b/lib/silcutil/silcstack.c index 79f63d2f..3fd06d33 100644 --- a/lib/silcutil/silcstack.c +++ b/lib/silcutil/silcstack.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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. */ diff --git a/lib/silcutil/silcstack.h b/lib/silcutil/silcstack.h index c4415a17..017a55d0 100644 --- a/lib/silcutil/silcstack.h +++ b/lib/silcutil/silcstack.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - 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 */