Back to index

citadel  8.12
Classes | Defines | Functions | Variables
threads.h File Reference
#include "sysdep.h"
#include <sys/time.h>
#include <string.h>
#include "server.h"
#include "sysdep_decls.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  thread_tsd

Defines

#define TSD   MyThread()

Functions

struct thread_tsdMyThread (void)
int try_critical_section (int which_one)
void begin_critical_section (int which_one)
void end_critical_section (int which_one)
void go_threading (void)
void InitializeMasterTSD (void)
void CtdlThreadCreate (void *(*start_routine)(void *))

Variables

int num_workers
int active_workers
int server_shutting_down

Class Documentation

struct thread_tsd

Definition at line 28 of file threads.h.

Class Members
DBC * cursors
DB_TXN * tid

Define Documentation

#define TSD   MyThread()

Definition at line 34 of file threads.h.


Function Documentation

void begin_critical_section ( int  which_one)

Definition at line 109 of file threads.c.

{
       /* For all types of critical sections except those listed here,
        * ensure nobody ever tries to do a critical section within a
        * transaction; this could lead to deadlock.
        */
       if (   (which_one != S_FLOORCACHE)
              && (which_one != S_RPLIST)
       ) {
              cdb_check_handles();
       }
       pthread_mutex_lock(&Critters[which_one]);
}

Here is the call graph for this function:

void CtdlThreadCreate ( void *(*)(void *)  start_routine)

Definition at line 168 of file threads.c.

{
       pthread_t thread;
       pthread_attr_t attr;
       int ret = 0;


       ret = pthread_attr_init(&attr);
       ret = pthread_attr_setstacksize(&attr, THREADSTACKSIZE);
       ret = pthread_create(&thread, &attr, CTC_backend, (void *)start_routine);
       if (ret != 0) syslog(LOG_EMERG, "pthread_create() : %s", strerror(errno));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void end_critical_section ( int  which_one)

Definition at line 126 of file threads.c.

{
       pthread_mutex_unlock(&Critters[which_one]);
}
void go_threading ( void  )

Definition at line 193 of file threads.c.

{
       if (pthread_key_create(&ThreadKey, NULL) != 0) {
              syslog(LOG_EMERG, "pthread_key_create() : %s", strerror(errno));
              abort();
       }

       /* Second call to module init functions now that threading is up */
       initialise_modules(1);

       /* Begin with one worker thread.  We will expand the pool if necessary */
       CtdlThreadCreate(worker_thread);

       /* The supervisor thread monitors worker threads and spawns more of them if it finds that
        * they are all in use.  FIXME make the 256 max threads a configurable value.
        */
       while (!server_shutting_down) {
              if ((active_workers == num_workers) && (num_workers < 256)) {
                     CtdlThreadCreate(worker_thread);
              }
              usleep(1000);
       }

       /* When we get to this point we are getting ready to shut down our Citadel server */
       if (!EventQShuttingDown)
       {
              EventQShuttingDown = 1;
              ShutDownEventQueues();
       }
       while (!EVQShutDown)
              usleep(1000);


       terminate_all_sessions();          /* close all client sockets */
       CtdlShutdownServiceHooks();        /* close all listener sockets to prevent new connections */
       PerformSessionHooks(EVT_SHUTDOWN); /* run any registered shutdown hooks */

       int countdown = 30;
       while ( (num_workers > 0) && (countdown-- > 0)) {
              syslog(LOG_DEBUG, "Waiting %d seconds for %d worker threads to exit",
                     countdown, num_workers
              );
              usleep(1000);
       }
}

Here is the call graph for this function:

void InitializeMasterTSD ( void  )

Definition at line 182 of file threads.c.

                               {
       memset(&masterTSD, 0, sizeof(struct thread_tsd));
}

Here is the caller graph for this function:

struct thread_tsd* MyThread ( void  ) [read]

Definition at line 137 of file threads.c.

                                  {
        register struct thread_tsd *c;
        return ((c = (struct thread_tsd *) pthread_getspecific(ThreadKey), c == NULL) ? &masterTSD : c);
}
int try_critical_section ( int  which_one)

Definition at line 91 of file threads.c.

{
       /* For all types of critical sections except those listed here,
        * ensure nobody ever tries to do a critical section within a
        * transaction; this could lead to deadlock.
        */
       if (   (which_one != S_FLOORCACHE)
              && (which_one != S_RPLIST)
       ) {
              cdb_check_handles();
       }
       return (pthread_mutex_trylock(&Critters[which_one]));
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 66 of file threads.c.

Definition at line 65 of file threads.c.

Definition at line 70 of file threads.c.