Kannel: Open Source WAP and SMS gateway  svn-r5335
counter.c File Reference
#include <limits.h>
#include "gwlib.h"

Go to the source code of this file.

Data Structures

struct  Counter
 

Macros

#define lock(c)   mutex_lock(c->lock)
 
#define unlock(c)   mutex_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)
 

Macro Definition Documentation

◆ lock

◆ unlock

#define unlock (   c)    mutex_unlock(c->lock)

Function Documentation

◆ counter_create()

Counter* counter_create ( void  )

Definition at line 94 of file counter.c.

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

Referenced by boxc_create(), client_thread(), dlr_init_spool(), eq_init(), init_batch(), init_bearerbox(), init_smppbox(), main(), port_add(), smasi_create(), smpp_create(), smsbox_start(), smsc2_start(), smsc_emu_init(), smsc_http_create(), 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().

95 {
97 
98  counter = gw_malloc(sizeof(Counter));
99 #ifdef HAVE_PTHREAD_SPINLOCK_T
100  pthread_spin_init(&counter->lock, 0);
101 #else
103 #endif
104 
105  counter->n = 0;
106  return counter;
107 }
#define mutex_create()
Definition: thread.h:96
Mutex * lock
Definition: counter.c:79
unsigned long n
Definition: counter.c:81
static Counter * counter

◆ counter_decrease()

unsigned long counter_decrease ( Counter counter)

Definition at line 155 of file counter.c.

References counter, lock, Counter::n, and unlock.

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

156 {
157  unsigned long ret;
158 
159  lock(counter);
160  ret = counter->n;
161  if (counter->n > 0)
162  --counter->n;
163  unlock(counter);
164  return ret;
165 }
#define unlock(c)
Definition: counter.c:90
#define lock(c)
Definition: counter.c:89
unsigned long n
Definition: counter.c:81
static Counter * counter

◆ counter_destroy()

void counter_destroy ( Counter counter)

Definition at line 110 of file counter.c.

References counter, Counter::lock, and mutex_destroy().

Referenced by boxc_cleanup(), boxc_destroy(), client_thread(), conndata_destroy(), dlr_spool_shutdown(), 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().

111 {
112  if (counter == NULL)
113  return;
114 
115 #ifdef HAVE_PTHREAD_SPINLOCK_T
116  pthread_spin_destroy(&counter->lock);
117 #else
119 #endif
120  gw_free(counter);
121 }
void mutex_destroy(Mutex *mutex)
Definition: thread.c:97
Mutex * lock
Definition: counter.c:79
static Counter * counter

◆ counter_increase()

◆ counter_increase_with()

unsigned long counter_increase_with ( Counter counter,
unsigned long  value 
)

Definition at line 134 of file counter.c.

References counter, lock, Counter::n, and unlock.

Referenced by smscconn_send().

135 {
136  unsigned long ret;
137 
138  lock(counter);
139  ret = counter->n;
140  counter->n += value;
141  unlock(counter);
142  return ret;
143 }
#define unlock(c)
Definition: counter.c:90
#define lock(c)
Definition: counter.c:89
unsigned long n
Definition: counter.c:81
static Counter * counter

◆ counter_set()

unsigned long counter_set ( Counter counter,
unsigned long  n 
)

Definition at line 167 of file counter.c.

References counter, lock, Counter::n, and unlock.

Referenced by dlr_spool_flush(), main(), and smscconn_send().

168 {
169  unsigned long ret;
170 
171  lock(counter);
172  ret = counter->n;
173  counter->n = n;
174  unlock(counter);
175  return ret;
176 }
#define unlock(c)
Definition: counter.c:90
#define lock(c)
Definition: counter.c:89
unsigned long n
Definition: counter.c:81
static Counter * counter

◆ counter_value()

unsigned long counter_value ( Counter counter)

Definition at line 145 of file counter.c.

References counter, lock, Counter::n, and unlock.

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

146 {
147  unsigned long ret;
148 
149  lock(counter);
150  ret = counter->n;
151  unlock(counter);
152  return ret;
153 }
#define unlock(c)
Definition: counter.c:90
#define lock(c)
Definition: counter.c:89
unsigned long n
Definition: counter.c:81
static Counter * counter
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.