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

counter.c File Reference

#include <limits.h>
#include "gwlib.h"

Include dependency graph for counter.c:

Include dependency graph

Go to the source code of this file.

Data Structures

struct  Counter

Defines

#define lock(c)   pthread_spin_lock(&c->lock)
#define unlock(c)   pthread_spin_unlock(&c->lock)

Functions

Countercounter_create (void)
void counter_destroy (Counter *counter)
unsigned long counter_increase (Counter *counter)
unsigned long counter_increase_with (Counter *counter, unsigned long value)
unsigned long counter_value (Counter *counter)
unsigned long counter_decrease (Counter *counter)
unsigned long counter_set (Counter *counter, unsigned long n)


Define Documentation

#define lock  )     pthread_spin_lock(&c->lock)
 

Definition at line 86 of file counter.c.

Referenced by counter_decrease(), counter_increase(), counter_increase_with(), counter_set(), counter_value(), dict_get(), dict_key_count(), dict_keys(), dict_put(), dict_put_true(), dict_remove(), gw_check_area_size(), gw_check_check_leaks(), gw_check_claim_area(), gw_check_free(), gw_check_is_allocated(), gw_check_malloc(), gw_check_realloc(), gw_gmtime(), gw_localtime(), gw_mktime(), gw_rand(), gw_rwlock_destroy(), gw_rwlock_init_static(), gw_rwlock_rdlock(), gw_rwlock_unlock(), gw_rwlock_wrlock(), gw_strftime(), gwlist_add_producer(), gwlist_append(), gwlist_append_unique(), gwlist_consume(), gwlist_delete(), gwlist_delete_equal(), gwlist_delete_matching(), gwlist_extract_first(), gwlist_extract_matching(), gwlist_get(), gwlist_insert(), gwlist_len(), gwlist_producer_count(), gwlist_remove_producer(), gwlist_search(), gwlist_search_all(), gwlist_sort(), gwlist_timed_consume(), gwlist_wait_until_nonempty(), gwthread_join(), gwthread_join_every(), gwthread_shutdown(), gwthread_wakeup(), gwtimer_start(), gwtimer_stop(), new_thread(), spawn_thread(), and watch_timers().

#define unlock  )     pthread_spin_unlock(&c->lock)
 

Definition at line 87 of file counter.c.

Referenced by counter_decrease(), counter_increase(), counter_increase_with(), counter_set(), counter_value(), dict_get(), dict_key_count(), dict_keys(), dict_put(), dict_put_true(), dict_remove(), gw_check_area_size(), gw_check_check_leaks(), gw_check_claim_area(), gw_check_free(), gw_check_is_allocated(), gw_check_malloc(), gw_check_realloc(), gw_gmtime(), gw_localtime(), gw_mktime(), gw_rand(), gw_strftime(), gwlist_add_producer(), gwlist_append(), gwlist_append_unique(), gwlist_consume(), gwlist_delete(), gwlist_delete_equal(), gwlist_delete_matching(), gwlist_extract_first(), gwlist_extract_matching(), gwlist_get(), gwlist_insert(), gwlist_len(), gwlist_producer_count(), gwlist_remove_producer(), gwlist_search(), gwlist_search_all(), gwlist_sort(), gwlist_timed_consume(), gwlist_wait_until_nonempty(), gwthread_join(), gwthread_join_every(), gwthread_shutdown(), gwthread_wakeup(), gwtimer_start(), gwtimer_stop(), new_thread(), spawn_thread(), and watch_timers().


Function Documentation

Counter* counter_create void   ) 
 

Definition at line 94 of file counter.c.

References Counter::lock, mutex_create, and Counter::n.

Referenced by client_thread(), eq_init(), init_bearerbox(), main(), port_add(), smasi_create(), smpp_create(), smsbox_start(), smsc2_start(), smsc_emu_init(), smscconn_create(), smscconn_send(), store_spool_init(), wap_appl_init(), wap_push_ppg_init(), wapbox_start(), wsp_push_client_init(), wsp_session_init(), wtp_initiator_init(), and wtp_resp_init().

00095 {
00096     Counter *counter;
00097 
00098     counter = gw_malloc(sizeof(Counter));
00099 #ifdef HAVE_PTHREAD_SPINLOCK_T
00100     pthread_spin_init(&counter->lock, 0);
00101 #else
00102     counter->lock = mutex_create();
00103 #endif
00104 
00105     counter->n = 0;
00106     return counter;
00107 }

unsigned long counter_decrease Counter counter  ) 
 

Definition at line 155 of file counter.c.

References lock, Counter::n, and unlock.

Referenced by get_receiver(), handle_split(), port_get_request(), return_reply(), and store_spool_save().

00156 {
00157     unsigned long ret;
00158 
00159     lock(counter);
00160     ret = counter->n;
00161     if (counter->n > 0)
00162         --counter->n;
00163     unlock(counter);
00164     return ret;
00165 }

void counter_destroy Counter counter  ) 
 

Definition at line 110 of file counter.c.

References Counter::lock, and mutex_destroy().

Referenced by boxc_cleanup(), client_thread(), empty_msg_lists(), eq_shutdown(), handle_split(), main(), port_remove(), smasi_destroy(), smpp_destroy(), smsc2_cleanup(), smsc_emu_shutdown(), smscconn_destroy(), smscconn_send(), store_spool_shutdown(), wap_appl_shutdown(), wap_push_ppg_shutdown(), wsp_push_client_shutdown(), wsp_session_shutdown(), wtp_initiator_shutdown(), and wtp_resp_shutdown().

00111 {
00112     if (counter == NULL)
00113         return;
00114 
00115 #ifdef HAVE_PTHREAD_SPINLOCK_T
00116     pthread_spin_destroy(&counter->lock);
00117 #else
00118     mutex_destroy(counter->lock);
00119 #endif
00120     gw_free(counter);
00121 }

Here is the call graph for this function:

unsigned long counter_increase Counter counter  ) 
 

Definition at line 123 of file counter.c.

References lock, Counter::n, and unlock.

Referenced by bb_smscconn_receive(), bb_smscconn_send_failed(), bb_smscconn_sent(), boxc_create(), check(), client_thread(), dispatch(), dispatch_datagram(), eq_create_event(), handle_submit_sm(), init_machine_create(), msg_to_pdu(), next_wsp_session_id(), open_connection(), open_receiver(), open_transceiver(), open_transmitter(), port_get_request(), push_client_machine_create(), push_machine_create(), push_thread(), remember_receiver(), resp_machine_create(), send_enquire_link(), send_logoff(), send_message(), send_smpp_thread(), send_unbind(), smpp_create(), smpp_emu_writer(), smsbox_thread(), smscconn_send(), start_fetch(), store_spool_save(), udp_receiver(), and udp_sender().

00124 {
00125     unsigned long ret;
00126 
00127     lock(counter);
00128     ret = counter->n;
00129     ++counter->n;
00130     unlock(counter);
00131     return ret;
00132 }

unsigned long counter_increase_with Counter counter,
unsigned long  value
 

Definition at line 134 of file counter.c.

References lock, Counter::n, and unlock.

Referenced by smscconn_send().

00135 {
00136     unsigned long ret;
00137 
00138     lock(counter);
00139     ret = counter->n;
00140     counter->n += value;
00141     unlock(counter);
00142     return ret;
00143 }

unsigned long counter_set Counter counter,
unsigned long  n
 

Definition at line 167 of file counter.c.

References lock, Counter::n, and unlock.

Referenced by smscconn_send().

00168 {
00169     unsigned long ret;
00170 
00171     lock(counter);
00172     ret = counter->n;
00173     counter->n = n;
00174     unlock(counter);
00175     return ret;
00176 }

unsigned long counter_value Counter counter  ) 
 

Definition at line 145 of file counter.c.

References lock, Counter::n, and unlock.

Referenced by bb_print_status(), empty_msg_lists(), main(), outstanding_requests(), port_remove(), send_smpp_thread(), smscconn_info(), store_spool_load(), store_spool_messages(), and wap_appl_get_load().

00146 {
00147     unsigned long ret;
00148 
00149     lock(counter);
00150     ret = counter->n;
00151     unlock(counter);
00152     return ret;
00153 }

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