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

gw-rwlock.h File Reference

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

Include dependency graph for gw-rwlock.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  RWLock

Functions

RWLockgw_rwlock_create (void)
void gw_rwlock_init_static (RWLock *lock)
void gw_rwlock_destroy (RWLock *lock)
int gw_rwlock_rdlock (RWLock *lock)
int gw_rwlock_unlock (RWLock *lock)
int gw_rwlock_wrlock (RWLock *lock)


Function Documentation

RWLock* gw_rwlock_create void   ) 
 

Definition at line 77 of file gw-rwlock.c.

References RWLock::dynamic, gwlist_create, panic, and RWLock::rwlock.

Referenced by smsbox_start().

00078 {
00079     RWLock *ret = gw_malloc(sizeof(*ret));
00080 #ifdef HAVE_PTHREAD_RWLOCK
00081     int rc = pthread_rwlock_init(&ret->rwlock, NULL);
00082     if (rc != 0)
00083         panic(rc, "Initialization of RWLock failed.");
00084 #else
00085     ret->writer = -1;
00086     ret->rwlock = gwlist_create();
00087     if (ret->rwlock == NULL)
00088         panic(0, "Initialization of RWLock failed.");
00089 #endif
00090     ret->dynamic = 1;
00091 
00092     return ret;
00093 }

void gw_rwlock_destroy RWLock lock  ) 
 

Definition at line 112 of file gw-rwlock.c.

References RWLock::dynamic, gwlist_destroy(), lock, panic, and RWLock::rwlock.

Referenced by dlr_mem_shutdown(), log_shutdown(), smsboxc_run(), and smsc2_cleanup().

00113 {
00114 #ifdef HAVE_PTHREAD_RWLOCK
00115     int ret;
00116 #endif
00117 
00118     if (!lock)
00119         return;
00120 
00121 #ifdef HAVE_PTHREAD_RWLOCK
00122     ret = pthread_rwlock_destroy(&lock->rwlock);
00123     if (ret != 0)
00124         panic(ret, "Attempt to destroy locked rwlock.");
00125 #else
00126     gwlist_destroy(lock->rwlock, NULL);
00127 #endif
00128 
00129     if (lock->dynamic)
00130         gw_free(lock);
00131 }

Here is the call graph for this function:

void gw_rwlock_init_static RWLock lock  ) 
 

Definition at line 96 of file gw-rwlock.c.

References RWLock::dynamic, gwlist_create, lock, panic, and RWLock::rwlock.

Referenced by dlr_init_mem(), log_init(), and smsc2_start().

00097 {
00098 #ifdef HAVE_PTHREAD_RWLOCK
00099     int rc = pthread_rwlock_init(&lock->rwlock, NULL);
00100     if (rc != 0)
00101         panic(rc, "Initialization of RWLock failed.");
00102 #else
00103     lock->writer = -1;
00104     lock->rwlock = gwlist_create();
00105     if (lock->rwlock == NULL)
00106         panic(0, "Initialization of RWLock failed.");
00107 #endif
00108     lock->dynamic = 0;
00109 }

int gw_rwlock_rdlock RWLock lock  ) 
 

Definition at line 134 of file gw-rwlock.c.

References gw_assert, gwlist_add_producer(), gwlist_lock(), gwlist_unlock(), lock, panic, RWDEBUG, and RWLock::rwlock.

Referenced by boxc_status(), dlr_mem_get(), route_incoming_to_boxc(), sms_to_smsboxes(), smsc2_resume(), smsc2_rout(), smsc2_shutdown(), smsc2_status(), smsc2_stop_smsc(), and smsc2_suspend().

00135 {
00136     int ret = 0;
00137     gw_assert(lock != NULL);
00138 
00139 #ifdef HAVE_PTHREAD_RWLOCK
00140     ret = pthread_rwlock_rdlock(&lock->rwlock);
00141     if (ret != 0) {
00142         panic(ret, "Error while pthread_rwlock_rdlock.");
00143     }
00144 #else
00145     gwlist_lock(lock->rwlock);
00146     gwlist_add_producer(lock->rwlock);
00147     gwlist_unlock(lock->rwlock);
00148     RWDEBUG("", 0, "------------ gw_rwlock_rdlock(%p) ----------", lock);
00149 #endif
00150 
00151     return ret;
00152 }

Here is the call graph for this function:

int gw_rwlock_unlock RWLock lock  ) 
 

Definition at line 155 of file gw-rwlock.c.

References gw_assert, gwlist_remove_producer(), gwlist_unlock(), gwthread_self(), lock, panic, RWDEBUG, and RWLock::rwlock.

Referenced by boxc_status(), dlr_mem_add(), dlr_mem_flush(), dlr_mem_get(), dlr_mem_remove(), dlr_mem_shutdown(), log_close_all(), log_open(), log_reopen(), route_incoming_to_boxc(), run_smsbox(), sms_to_smsboxes(), smsc2_cleanup(), smsc2_restart_smsc(), smsc2_resume(), smsc2_rout(), smsc2_shutdown(), smsc2_status(), smsc2_stop_smsc(), and smsc2_suspend().

00156 {
00157     int ret = 0;
00158     gw_assert(lock != NULL);
00159 
00160 #ifdef HAVE_PTHREAD_RWLOCK
00161     ret = pthread_rwlock_unlock(&lock->rwlock);
00162     if (ret != 0)
00163         panic(ret, "Error while gw_rwlock_unlock.");
00164 #else
00165     RWDEBUG("", 0, "------------ gw_rwlock_unlock(%p) ----------", lock);
00166     if (lock->writer == gwthread_self()) {
00167         lock->writer = -1;
00168         gwlist_unlock(lock->rwlock);
00169     } else 
00170         gwlist_remove_producer(lock->rwlock);
00171 #endif
00172 
00173     return ret;
00174 }

Here is the call graph for this function:

int gw_rwlock_wrlock RWLock lock  ) 
 

Definition at line 177 of file gw-rwlock.c.

References gw_assert, gwlist_consume(), gwlist_lock(), gwlist_producer_count(), gwthread_self(), lock, panic, RWDEBUG, and RWLock::rwlock.

Referenced by dlr_mem_add(), dlr_mem_flush(), dlr_mem_remove(), dlr_mem_shutdown(), log_close_all(), log_open(), log_reopen(), run_smsbox(), smsc2_cleanup(), and smsc2_restart_smsc().

00178 {
00179     int ret = 0;
00180     gw_assert(lock != NULL);
00181 
00182 #ifdef HAVE_PTHREAD_RWLOCK
00183     ret = pthread_rwlock_wrlock(&lock->rwlock);
00184     if (ret != 0)
00185         panic(ret, "Error while pthread_rwlock_wrlock.");
00186 #else
00187     RWDEBUG("", 0, "------------ gw_rwlock_wrlock(%p) ----------", lock);
00188     gwlist_lock(lock->rwlock);
00189     RWDEBUG("", 0, "------------ gw_rwlock_wrlock(%p) producers=%d", lock, gwlist_producer_count(lock->rwlock));
00190     /* wait for reader */
00191     gwlist_consume(lock->rwlock);
00192     lock->writer = gwthread_self();
00193 #endif
00194 
00195     return ret;
00196 }

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.