Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

thread.h File Reference

#include "gw-config.h"
#include <pthread.h>

Include dependency graph for thread.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  Mutex

Defines

#define mutex_create()   gw_claim_area(mutex_create_real())
#define mutex_init_static(mutex)   mutex_init_static_real(mutex)
#define mutex_lock(m)   mutex_lock_real(m, __FILE__, __LINE__, __func__)
#define mutex_unlock(m)   mutex_unlock_real(m, __FILE__, __LINE__, __func__)
#define mutex_trylock(m)   mutex_trylock_real(m, __FILE__, __LINE__, __func__)

Functions

Mutexmutex_create_measured (Mutex *mutex, unsigned char *filename, int lineno)
Mutexmutex_create_real (void)
Mutexmutex_init_static_real (Mutex *mutex)
void mutex_destroy (Mutex *mutex)
void mutex_lock_real (Mutex *mutex, char *file, int line, const char *func)
int mutex_unlock_real (Mutex *mutex, char *file, int line, const char *func)
int mutex_trylock_real (Mutex *mutex, const char *file, int line, const char *func)


Define Documentation

 
#define mutex_create  )     gw_claim_area(mutex_create_real())
 

Definition at line 96 of file thread.h.

Referenced by bearerbox_address_create(), client_init(), conn_pool_init(), conn_wrap_fd(), counter_create(), dict_create(), gw_prioqueue_create(), gwlist_create_real(), init_bearerbox(), init_concat_handler(), main(), openssl_init_locks(), port_init(), proxy_init(), radius_acct_init(), server_init(), smsc_wrapper_create(), smscconn_create(), smscenter_construct(), store_file_init(), and timers_init().

#define mutex_init_static mutex   )     mutex_init_static_real(mutex)
 

Definition at line 116 of file thread.h.

Referenced by gw_check_init_mem(), gwlib_protected_init(), and octstr_init().

#define mutex_lock  )     mutex_lock_real(m, __FILE__, __LINE__, __func__)
 

Definition at line 131 of file thread.h.

Referenced by at2_device_thread(), bb_isolate(), bb_resume(), bb_shutdown(), bb_suspend(), cgw_open_send_connection(), cgw_sender(), check_concatenation(), check_pool_conn(), cimd2_submit_msg(), clear_old_concat_parts(), client_session(), conn_pool_get(), conn_pool_put(), emi2_sender(), fake_listener(), get_next_transaction(), gwlist_lock(), handle_pdu(), http_close_proxy(), http_use_proxy(), io_thread(), lock(), lock_in(), lock_out(), octstr_imm(), oisd_submit_msg(), open_send_connection(), openssl_locking_function(), pack_server_address(), port_add(), port_get_request(), port_put_request(), port_remove(), print_data(), print_msg(), proxy_thread(), proxy_used_for_host(), queue_lock(), radius_acct_get_msisdn(), radius_acct_shutdown(), reconnect(), sms_receive(), smscconn_destroy(), smscconn_info(), smscconn_send(), smscconn_shutdown(), smscconn_start(), smscconn_stop(), smscenter_lock(), soap_listener(), start_client_threads(), start_server_thread(), store_file_dump(), store_file_load(), store_file_save(), wap_push_ota_bb_address_set(), and wrapper_sender().

#define mutex_trylock  )     mutex_trylock_real(m, __FILE__, __LINE__, __func__)
 

Definition at line 145 of file thread.h.

#define mutex_unlock  )     mutex_unlock_real(m, __FILE__, __LINE__, __func__)
 

Definition at line 137 of file thread.h.

Referenced by at2_device_thread(), bb_isolate(), bb_resume(), bb_shutdown(), bb_suspend(), cgw_open_send_connection(), cgw_sender(), check_concatenation(), check_pool_conn(), cimd2_submit_msg(), clear_old_concat_parts(), client_session(), conn_pool_get(), conn_pool_put(), emi2_sender(), fake_listener(), get_next_transaction(), gwlist_unlock(), handle_pdu(), http_close_proxy(), http_use_proxy(), io_thread(), octstr_imm(), oisd_submit_msg(), open_send_connection(), openssl_locking_function(), pack_server_address(), port_add(), port_get_request(), port_put_request(), port_remove(), print_data(), print_msg(), proxy_thread(), proxy_used_for_host(), queue_unlock(), radius_acct_get_msisdn(), radius_acct_shutdown(), reconnect(), sms_receive(), smscconn_destroy(), smscconn_info(), smscconn_send(), smscconn_shutdown(), smscconn_start(), smscconn_stop(), smscenter_unlock(), soap_listener(), start_client_threads(), start_server_thread(), store_file_dump(), store_file_load(), store_file_save(), unlock(), unlock_in_real(), unlock_out_real(), wap_push_ota_bb_address_set(), and wrapper_sender().


Function Documentation

Mutex* mutex_create_measured Mutex mutex,
unsigned char *  filename,
int  lineno
 

Mutex* mutex_create_real void   ) 
 

Definition at line 78 of file thread.c.

References Mutex::dynamic, Mutex::mutex, mutex, and Mutex::owner.

00079 {
00080     Mutex *mutex;
00081 
00082     mutex = gw_malloc(sizeof(Mutex));
00083     pthread_mutex_init(&mutex->mutex, NULL);
00084     mutex->owner = -1;
00085     mutex->dynamic = 1;
00086     return mutex;
00087 }

void mutex_destroy Mutex mutex  ) 
 

Definition at line 97 of file thread.c.

References Mutex::dynamic, info(), Mutex::mutex, mutex, and panic.

Referenced by bearerbox_address_destroy(), client_shutdown(), conn_destroy(), conn_pool_shutdown(), counter_destroy(), dict_destroy(), gw_check_shutdown(), gw_prioqueue_destroy(), gwlib_protected_shutdown(), gwlist_destroy(), main(), octstr_shutdown(), openssl_shutdown_locks(), port_shutdown(), proxy_shutdown(), radius_acct_shutdown(), server_shutdown(), shutdown_concat_handler(), smscconn_destroy(), smscenter_destruct(), smscwrapper_destroy(), store_dumper(), and timers_shutdown().

00098 {
00099     int ret;
00100 
00101     if (mutex == NULL)
00102         return;
00103 
00104 #ifdef MUTEX_STATS
00105     if (mutex->locks > 0 || mutex->collisions > 0) {
00106         info(0, "Mutex %s:%d: %ld locks, %ld collisions.",
00107              mutex->filename, mutex->lineno,
00108              mutex->locks, mutex->collisions);
00109     }
00110 #endif
00111 
00112     if ((ret = pthread_mutex_destroy(&mutex->mutex)) != 0)
00113         panic(ret, "Attempt to destroy locked mutex!");
00114 
00115     if (mutex->dynamic == 0)
00116         return;
00117     gw_free(mutex);
00118 }

Here is the call graph for this function:

Mutex* mutex_init_static_real Mutex mutex  ) 
 

Definition at line 89 of file thread.c.

References Mutex::dynamic, Mutex::mutex, mutex, and Mutex::owner.

00090 {
00091     pthread_mutex_init(&mutex->mutex, NULL);
00092     mutex->owner = -1;
00093     mutex->dynamic = 0;
00094     return mutex;
00095 }

void mutex_lock_real Mutex mutex,
char *  file,
int  line,
const char *  func
 

Definition at line 121 of file thread.c.

References file, gw_assert, gwthread_self(), Mutex::mutex, mutex, Mutex::owner, and panic.

00122 {
00123     int ret;
00124 
00125     gw_assert(mutex != NULL);
00126 
00127 #ifdef MUTEX_STATS
00128     ret = pthread_mutex_trylock(&mutex->mutex);
00129     if (ret != 0) {
00130         ret = pthread_mutex_lock(&mutex->mutex);
00131         mutex->collisions++;
00132     }
00133     mutex->locks++;
00134 #else
00135     ret = pthread_mutex_lock(&mutex->mutex);
00136 #endif
00137     if (ret != 0)
00138         panic(0, "%s:%ld: %s: Mutex failure! (Called from %s:%ld:%s.)", \
00139                  __FILE__, (long) __LINE__, __func__, file, (long) line, func);
00140     if (mutex->owner == gwthread_self())
00141         panic(0, "%s:%ld: %s: Managed to lock the mutex twice! (Called from %s:%ld:%s.)", \
00142                  __FILE__, (long) __LINE__, __func__, file, (long) line, func);
00143     mutex->owner = gwthread_self();
00144 }

Here is the call graph for this function:

int mutex_trylock_real Mutex mutex,
const char *  file,
int  line,
const char *  func
 

Definition at line 165 of file thread.c.

References error(), file, gwthread_self(), Mutex::mutex, mutex, Mutex::owner, and panic.

00166 {
00167     int ret;
00168 
00169     if (mutex == NULL) {
00170         error(0, "%s:%ld: %s: Trying to lock a NULL mutex! (Called from %s:%ld:%s.)", \
00171                  __FILE__, (long) __LINE__, __func__, file, (long) line, func);
00172         return -1;
00173     }
00174 
00175     ret = pthread_mutex_trylock(&mutex->mutex);
00176     if (ret == 0) {
00177         if (mutex->owner == gwthread_self())
00178             panic(0, "%s:%ld: %s: Managed to lock the mutex twice! (Called from %s:%ld:%s.)", \
00179                  __FILE__, (long) __LINE__, __func__, file, (long) line, func);
00180 
00181         mutex->owner = gwthread_self();
00182     }
00183     else if (ret == EINVAL)
00184         panic(0, "%s:%ld: %s: Mutex failure! (Called from %s:%ld:%s.)", \
00185                  __FILE__, (long) __LINE__, __func__, file, (long) line, func);
00186 
00187     return ret;
00188 }

Here is the call graph for this function:

int mutex_unlock_real Mutex mutex,
char *  file,
int  line,
const char *  func
 

Definition at line 146 of file thread.c.

References error(), file, gw_assert, Mutex::mutex, mutex, Mutex::owner, and panic.

00147 {
00148      int ret;
00149     
00150     if (mutex == NULL) {
00151         error(0, "%s:%ld: %s: Trying to unlock a NULL mutex! (Called from %s:%ld:%s.)", \
00152                  __FILE__, (long) __LINE__, __func__, file, (long) line, func);
00153        return -1;
00154     }
00155     gw_assert(mutex != NULL);
00156     mutex->owner = -1;
00157     ret = pthread_mutex_unlock(&mutex->mutex);
00158     if (ret != 0)
00159         panic(0, "%s:%ld: %s: Mutex failure! (Called from %s:%ld:%s.)", \
00160                  __FILE__, (long) __LINE__, __func__, file, (long) line, func);
00161 
00162     return ret;
00163 }

Here is the call graph for this function:

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.