Asterisk - The Open Source Telephony Project  18.5.0
Functions
astobj2_global.c File Reference

Functions implementing ao2_global_obj routines. More...

#include "asterisk.h"
#include "asterisk/astobj2.h"
#include "asterisk/utils.h"
Include dependency graph for astobj2_global.c:

Go to the source code of this file.

Functions

void * __ao2_global_obj_ref (struct ao2_global_obj *holder, const char *tag, const char *file, int line, const char *func, const char *name)
 
void * __ao2_global_obj_replace (struct ao2_global_obj *holder, void *obj, const char *tag, const char *file, int line, const char *func, const char *name)
 
int __ao2_global_obj_replace_unref (struct ao2_global_obj *holder, void *obj, const char *tag, const char *file, int line, const char *func, const char *name)
 

Detailed Description

Functions implementing ao2_global_obj routines.

Author
Richard Mudgett rmudg.nosp@m.ett@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file astobj2_global.c.

Function Documentation

◆ __ao2_global_obj_ref()

void* __ao2_global_obj_ref ( struct ao2_global_obj holder,
const char *  tag,
const char *  file,
int  line,
const char *  func,
const char *  name 
)

Definition at line 72 of file astobj2_global.c.

References __ao2_ref(), __ast_rwlock_rdlock(), __ast_rwlock_unlock(), ast_assert, ast_log, ao2_global_obj::lock, LOG_ERROR, NULL, and ao2_global_obj::obj.

73 {
74  void *obj;
75 
76  if (!holder) {
77  /* For sanity */
78  ast_log(LOG_ERROR, "Must be called with a global object!\n");
79  ast_assert(0);
80  return NULL;
81  }
82 
83  if (__ast_rwlock_rdlock(file, line, func, &holder->lock, name)) {
84  /* Could not get the read lock. */
85  ast_assert(0);
86  return NULL;
87  }
88 
89  obj = holder->obj;
90  if (obj) {
91  __ao2_ref(obj, +1, tag, file, line, func);
92  }
93 
94  __ast_rwlock_unlock(file, line, func, &holder->lock, name);
95 
96  return obj;
97 }
int __ast_rwlock_rdlock(const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
Definition: lock.c:819
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
int __ast_rwlock_unlock(const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
Definition: lock.c:748
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:498
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
void * obj
Definition: astobj2.h:808
static const char name[]
Definition: cdr_mysql.c:74
ast_rwlock_t lock
Definition: astobj2.h:806

◆ __ao2_global_obj_replace()

void* __ao2_global_obj_replace ( struct ao2_global_obj holder,
void *  obj,
const char *  tag,
const char *  file,
int  line,
const char *  func,
const char *  name 
)

Definition at line 33 of file astobj2_global.c.

References __ao2_ref(), __ast_rwlock_unlock(), __ast_rwlock_wrlock(), ast_assert, ast_log, ao2_global_obj::lock, LOG_ERROR, NULL, and ao2_global_obj::obj.

Referenced by __ao2_global_obj_replace_unref().

34 {
35  void *obj_old;
36 
37  if (!holder) {
38  /* For sanity */
39  ast_log(LOG_ERROR, "Must be called with a global object!\n");
40  ast_assert(0);
41  return NULL;
42  }
43  if (__ast_rwlock_wrlock(file, line, func, &holder->lock, name)) {
44  /* Could not get the write lock. */
45  ast_assert(0);
46  return NULL;
47  }
48 
49  if (obj) {
50  __ao2_ref(obj, +1, tag, file, line, func);
51  }
52  obj_old = holder->obj;
53  holder->obj = obj;
54 
55  __ast_rwlock_unlock(file, line, func, &holder->lock, name);
56 
57  return obj_old;
58 }
#define ast_assert(a)
Definition: utils.h:695
#define NULL
Definition: resample.c:96
int __ast_rwlock_unlock(const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
Definition: lock.c:748
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:498
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
void * obj
Definition: astobj2.h:808
static const char name[]
Definition: cdr_mysql.c:74
ast_rwlock_t lock
Definition: astobj2.h:806
int __ast_rwlock_wrlock(const char *filename, int lineno, const char *func, ast_rwlock_t *t, const char *name)
Definition: lock.c:917

◆ __ao2_global_obj_replace_unref()

int __ao2_global_obj_replace_unref ( struct ao2_global_obj holder,
void *  obj,
const char *  tag,
const char *  file,
int  line,
const char *  func,
const char *  name 
)

Definition at line 60 of file astobj2_global.c.

References __ao2_global_obj_replace(), and __ao2_ref().

61 {
62  void *obj_old;
63 
64  obj_old = __ao2_global_obj_replace(holder, obj, tag, file, line, func, name);
65  if (obj_old) {
66  __ao2_ref(obj_old, -1, tag, file, line, func);
67  return 1;
68  }
69  return 0;
70 }
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:498
static const char name[]
Definition: cdr_mysql.c:74
void * __ao2_global_obj_replace(struct ao2_global_obj *holder, void *obj, const char *tag, const char *file, int line, const char *func, const char *name)