File modules/th/thread.c

  $Revision: 1.12 $

Example code: A thread.
Status: NOT REVUED, NOT TESTED
Authors: Chris Ottrey Joao Damas
Online References:

Included Files


Preprocessor definitions

String sizes

#define STR_S 63

#define STR_M 255

#define STR_L 1023

#define STR_XL 4095

#define STR_XXL 16383


Typedef th_args

typedef struct th_args th_args
struct th_args 
   { 
     void* function; 
     int sock; 
   } 

Global Variable Whois_thread_count_lock

Mutex lock. Used for synchronizing changes.

pthread_mutex_t Whois_thread_count_lock
Visible in:  modules/th/thread.c
Used in: TH_do_whois()modules/th/thread.c


Global Variable Config_thread_count_lock

pthread_mutex_t Config_thread_count_lock
Visible in:  modules/th/thread.c

Global Variable Mirror_thread_count_lock

pthread_mutex_t Mirror_thread_count_lock
Visible in:  modules/th/thread.c

Global Variable Whois_thread_count

The number of threads.

int Whois_thread_count
Visible in:  modules/th/thread.c
Used in: TH_do_whois()modules/th/thread.c


Global Variable Config_thread_count

int Config_thread_count
Visible in:  modules/th/thread.c

Global Variable Mirror_thread_count

int Mirror_thread_count
Visible in:  modules/th/thread.c

Global Function TH_acquire_read_lock()

  Aquire a readers lock.

Reference: "Multithreaded Programming Techniques - Prasad p.192" More:
  Author:
        ottrey
void TH_acquire_read_lock ( rw_lock_t* prw_lock )
rw_lock_t* prw_lock
Readers writers lock.
Prototyped in: modules/th/thread.h
Calls: pthread_cond_wait(), pthread_mutex_lock(), pthread_mutex_unlock()
Called by: AC_check_acl()modules/ac/access_control.c
  AC_fetch_acc()modules/ac/access_control.c

Global Function TH_acquire_write_lock()

  Aquire a writers lock.

Reference: "Multithreaded Programming Techniques - Prasad p.192" More:
  Author:
        ottrey
void TH_acquire_write_lock ( rw_lock_t* prw_lock )
rw_lock_t* prw_lock
Readers writers lock.
Prototyped in: modules/th/thread.h
Calls: pthread_cond_wait(), pthread_mutex_lock(), pthread_mutex_unlock()
Called by: AC_acc_load()modules/ac/access_control.c
  AC_commit()modules/ac/access_control.c
  AC_decay()modules/ac/access_control.c

Global Function TH_do_config()

  Handle config connections.

More:
  Author:
        joao
void TH_do_config ( void* arg )
void* arg
The socket to connect to. (It has to be passed in this way for this thread routine.)
Prototyped in: modules/th/thread.h
Calls: PC_interact()modules/pc/protocol_config.c
  log_print()modules/sk/socket.c
  pthread_exit(), pthread_self(), sprintf(), strcpy()
Used in: SV_start()modules/sv/server.c

Global Function TH_do_whois()

  Handle whois connections.

More:
  Author:
        joao
void TH_do_whois ( void* arg )
void* arg
The socket to connect to. (It has to be passed in this way for this thread routine.)
Prototyped in: modules/th/thread.h
Calls: PW_interact()modules/pw/protocol_whois.c
  log_print()modules/sk/socket.c
  pthread_exit(), pthread_mutex_lock(), pthread_mutex_unlock(), pthread_self(), sprintf(), strcpy()
Used in: SV_start()modules/sv/server.c
References Variables: Whois_thread_countmodules/th/thread.c
  Whois_thread_count_lockmodules/th/thread.c

Global Function TH_get_id()

int TH_get_id ( void )
Prototyped in: modules/th/thread.h
Calls: pthread_self()
Called by: log_config()modules/pc/protocol_config.c

Global Function TH_hdl_signal()

  Handle signals.

Changes the flags: do_nrtm do_update do_whoisd
More:
  Author:
        andrei
void TH_hdl_signal ( void )
Prototyped in: modules/th/thread.h
Calls: CO_set_const()modules/co/constants.c
  log_print()modules/sk/socket.c
  pthread_exit(), pthread_sigmask(), sigaddset(), sigemptyset(), sigwait(), sprintf(), strcpy()

Global Function TH_init_read_write_lock()

  Initialize a readers/writers lock.

Side effect: the lock is set to open(?)
Reference: "Multithreaded Programming Techniques - Prasad p.192" More:
  Author:
        ottrey
void TH_init_read_write_lock ( rw_lock_t* prw_lock )
rw_lock_t* prw_lock
Readers writers lock.
Prototyped in: modules/th/thread.h
Calls: pthread_cond_init(), pthread_mutex_init()
Called by: RX_tree_cre()modules/rx/rx_tree.c

Global Function TH_release_read_lock()

  Release a readers lock.

Reference: "Multithreaded Programming Techniques - Prasad p.192" More:
  Author:
        ottrey
void TH_release_read_lock ( rw_lock_t* prw_lock )
rw_lock_t* prw_lock
Readers writers lock.
Prototyped in: modules/th/thread.h
Calls: pthread_cond_signal(), pthread_mutex_lock(), pthread_mutex_unlock()
Called by: AC_check_acl()modules/ac/access_control.c
  AC_fetch_acc()modules/ac/access_control.c

Global Function TH_release_write_lock()

  Release a writers lock.

Reference: "Multithreaded Programming Techniques - Prasad p.192" More:
  Author:
        ottrey
void TH_release_write_lock ( rw_lock_t* prw_lock )
rw_lock_t* prw_lock
Readers writers lock.
Prototyped in: modules/th/thread.h
Calls: pthread_cond_broadcast(), pthread_mutex_lock(), pthread_mutex_unlock()
Called by: AC_acc_load()modules/ac/access_control.c
  AC_commit()modules/ac/access_control.c
  AC_decay()modules/ac/access_control.c

Global Function TH_run()

  This is the routine that creates the main threads. 

More:
  Author:
        ottrey
	joao
void TH_run ( int sock, void* do_function(void*) )
int sock
The socket to connect to. void * do_function The function to call for each type of service
void* do_function(void*)
 
Prototyped in: modules/th/thread.h
Calls: CO_get_max_threads()modules/co/constants.c
  PW_interact()modules/pw/protocol_whois.c
  SK_accept_connection()modules/sk/socket.c
  log_print()modules/sk/socket.c
  fprintf(), pthread_attr_init(), pthread_attr_setdetachstate(), pthread_create(), sprintf(), strcpy(), wr_real_calloc()
Called by: SV_start()modules/sv/server.c
References Functions: main_thread()modules/th/thread.c

Global Function TH_run1()

  This is the routine that creates 1 main thread. 

More:
  Author:
        ottrey
	joao
	andrei
void TH_run1 ( int sock, void* do_function(void*) )
int sock
The socket to listen to. void * do_function The function to call for each type of service
void* do_function(void*)
 
Prototyped in: modules/th/thread.h
Calls: pthread_attr_init(), pthread_attr_setdetachstate(), pthread_create()
Called by: SV_start()modules/sv/server.c

Global Function TH_run2()

void TH_run2 ( void* function(void*) )
Prototyped in: modules/th/thread.h
Calls: pthread_attr_init(), pthread_attr_setdetachstate(), pthread_create()
Called by: AC_acc_load()modules/ac/access_control.c
  SV_start()modules/sv/server.c

Global Function TH_to_string()

char* TH_to_string ( void )
Prototyped in: modules/th/thread.h
Calls: fprintf(), pthread_self(), sprintf(), strcat(), strcpy(), strlen(), wr_real_malloc()
Called by: show_thread()modules/pc/protocol_config.c

Local Function log_print()

static void log_print ( const char* arg )
Calls: CO_get_thread_logfile()modules/co/constants.c
  CO_get_thread_logging()modules/co/constants.c
  fclose(), fopen(), fprintf(), printf(), strcmp()
Called by: TH_do_config()modules/th/thread.c
  TH_do_whois()modules/th/thread.c
  TH_hdl_signal()modules/th/thread.c
  TH_run()modules/th/thread.c

Local Function main_thread()

  Waits for an incoming connection on the and spawns a new thread to handle it.

More:
  Author:
        ottrey
	joao
static void* main_thread ( void* arg )
void* arg
Pointer to a struct containing the socket to talk to the client and the function to call depending on the incoming connection.
Calls: SK_accept_connection()modules/sk/socket.c
  pthread_attr_init(), pthread_attr_setdetachstate(), pthread_create()
Used in: TH_run()modules/th/thread.c