| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
#include "asterisk.h" |
| 29 |
|
| 30 |
#include "asterisk/astobj2.h" |
| 31 |
#include "asterisk/utils.h" |
| 32 |
|
| 33 |
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) |
| 34 |
{ |
| 35 |
void *obj_old; |
| 36 |
|
| 37 |
if (!holder) { |
| 38 |
|
| 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 |
|
| 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 |
} |
| 59 |
|
| 60 |
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) |
| 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 |
} |
| 71 |
|
| 72 |
void *__ao2_global_obj_ref(struct ao2_global_obj *holder, const char *tag, const char *file, int line, const char *func, const char *name) |
| 73 |
{ |
| 74 |
void *obj; |
| 75 |
|
| 76 |
if (!holder) { |
| 77 |
|
| 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 |
|
| 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 |
} |