Cross reference for modules/th/thread.c of index.

# File modules/th/thread.c

      $Revision: 1.8 $

      Example code: A thread.

      Status: NOT REVUED, NOT TESTED

     Authors:       Chris Ottrey
    		Joao Damas

    Online References:

## Included Files

- `#include "modules/th/thread.h"`
  - `#include <pthread.h>`

- `#include <stdio.h>`

- `#include "include/protocol_config.h"`

- `#include "include/constants.h"`

## 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_check_acl() | 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_count | modules/th/thread.c
| Whois_thread_count_lock | modules/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_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: | cond_init(), 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_check_acl() | 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 )`

`int sock`
  The socket to connect to. void * do_function The function to call for each type of service
`void* do_function`

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
| calloc(), pthread_attr_init(), pthread_attr_setdetachstate(), pthread_create(), sprintf(), strcpy()
Called by: | SV_start() | modules/sv/server.c
References Functions: | main_thread() | modules/th/thread.c

## Global Function TH_run2()

`void TH_run2 ( void* function )`

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

## Global Function TH_to_string()

`char* TH_to_string ( void )`

Prototyped in: | modules/th/thread.h
Calls: | calloc(), pthread_self(), sprintf(), strcat(), strcpy(), strlen()
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_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