From bb4db7b4e2620965dd7a57984d8f7d07ca4b4806 Mon Sep 17 00:00:00 2001 From: Dave West Date: Tue, 18 Mar 2008 14:58:28 +0000 Subject: [PATCH] Created a routine to get a copy of the context list so that it can be read safely at leasure. --- citadel/include/ctdl_module.h | 10 ++++++++++ citadel/sysdep.c | 18 ++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/citadel/include/ctdl_module.h b/citadel/include/ctdl_module.h index e5a544b73..5dc418131 100644 --- a/citadel/include/ctdl_module.h +++ b/citadel/include/ctdl_module.h @@ -138,5 +138,15 @@ void CtdlThreadAllocTSD(void); #define MYTID (((ThreadTSD*)pthread_getspecific(ThreadKey))->tid) #define CT (((ThreadTSD*)pthread_getspecific(ThreadKey))->self) +/** return the current context list as an array and do it in a safe manner + * The returned data is a copy so only reading is useful + * The number of contexts is returned in count. + * Beware, this does not copy any of the data pointed to by the context. + * This means that you can not rely on things like the redirect buffer being valid. + * You must free the returned pointer when done. + */ +struct CitContext *CtdlGetContextArray (int *count); + + #endif /* CTDL_MODULE_H */ diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 164cafd5a..bf77408ee 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -460,6 +460,24 @@ struct CitContext *CreateNewContext(void) { } +struct CitContext *CtdlGetContextArray(int *count) +{ + int nContexts, i; + struct CitContext *nptr, *cptr; + + nContexts = num_sessions; + nptr = malloc(sizeof(struct CitContext) * nContexts); + if (!nptr) + return NULL; + begin_critical_section(S_SESSION_TABLE); + for (cptr = ContextList, i=0; cptr != NULL && i < nContexts; cptr = cptr->next, i++) + memcpy(&nptr[i], cptr, sizeof (struct CitContext)); + end_critical_section (S_SESSION_TABLE); + + *count = i; + return nptr; +} + /* * The following functions implement output buffering. If the kernel supplies * native TCP buffering (Linux & *BSD), use that; otherwise, emulate it with -- 2.30.2