Asterisk - The Open Source Telephony Project  GIT-master-b7027de
Macros | Functions
astobj2_private.h File Reference

Common, private definitions for astobj2. More...

#include "asterisk/astobj2.h"

Go to the source code of this file.

Macros

#define __is_ao2_object(user_data, file, line, func)
 
#define AO2_DEVMODE_STAT(stat)
 
#define is_ao2_object(user_data)   __is_ao2_object(user_data, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 

Functions

enum ao2_lock_req __adjust_lock (void *user_data, enum ao2_lock_req lock_how, int keep_stronger)
 
int internal_is_ao2_object (void *user_data)
 
void log_bad_ao2 (void *user_data, const char *file, int line, const char *func)
 

Detailed Description

Common, private definitions for astobj2.

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

Definition in file astobj2_private.h.

Macro Definition Documentation

◆ __is_ao2_object

#define __is_ao2_object (   user_data,
  file,
  line,
  func 
)

◆ AO2_DEVMODE_STAT

#define AO2_DEVMODE_STAT (   stat)

◆ is_ao2_object

#define is_ao2_object (   user_data)    __is_ao2_object(user_data, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Function Documentation

◆ __adjust_lock()

enum ao2_lock_req __adjust_lock ( void *  user_data,
enum ao2_lock_req  lock_how,
int  keep_stronger 
)

Definition at line 425 of file astobj2.c.

References __adjust_lock(), AO2_ALLOC_OPT_LOCK_MASK, AO2_ALLOC_OPT_LOCK_MUTEX, AO2_ALLOC_OPT_LOCK_NOLOCK, AO2_ALLOC_OPT_LOCK_OBJ, AO2_ALLOC_OPT_LOCK_RWLOCK, AO2_LOCK_REQ_MUTEX, AO2_LOCK_REQ_RDLOCK, AO2_LOCK_REQ_WRLOCK, ao2_rdlock, ao2_unlock, ao2_wrlock, ast_log, INTERNAL_OBJ, INTERNAL_OBJ_LOCKOBJ, INTERNAL_OBJ_RWLOCK, ao2_lockobj_priv::lock, astobj2_lockobj::lockobj, LOG_ERROR, ao2_rwlock_priv::num_lockers, __priv_data::options, astobj2::priv_data, and astobj2_rwlock::rwlock.

Referenced by __adjust_lock(), __ao2_iterator_next(), __ao2_link(), __ao2_weakproxy_find(), ao2_iterator_restart(), hash_ao2_node_destructor(), internal_ao2_traverse(), and rb_ao2_node_destructor().

426 {
427  struct astobj2 *obj = INTERNAL_OBJ(user_data);
428  struct astobj2_rwlock *obj_rwlock;
429  struct astobj2_lockobj *obj_lockobj;
430  enum ao2_lock_req orig_lock;
431 
432  switch (obj->priv_data.options & AO2_ALLOC_OPT_LOCK_MASK) {
434  obj_rwlock = INTERNAL_OBJ_RWLOCK(user_data);
435  if (obj_rwlock->rwlock.num_lockers < 0) {
436  orig_lock = AO2_LOCK_REQ_WRLOCK;
437  } else {
438  orig_lock = AO2_LOCK_REQ_RDLOCK;
439  }
440  switch (lock_how) {
441  case AO2_LOCK_REQ_MUTEX:
442  lock_how = AO2_LOCK_REQ_WRLOCK;
443  /* Fall through */
444  case AO2_LOCK_REQ_WRLOCK:
445  if (lock_how != orig_lock) {
446  /* Switch from read lock to write lock. */
449  }
450  break;
451  case AO2_LOCK_REQ_RDLOCK:
452  if (!keep_stronger && lock_how != orig_lock) {
453  /* Switch from write lock to read lock. */
456  }
457  break;
458  }
459  break;
461  obj_lockobj = INTERNAL_OBJ_LOCKOBJ(user_data);
462  orig_lock = __adjust_lock(obj_lockobj->lockobj.lock, lock_how, keep_stronger);
463  break;
464  default:
465  ast_log(LOG_ERROR, "Invalid lock option on ao2 object %p\n", user_data);
466  /* Fall through */
469  orig_lock = AO2_LOCK_REQ_MUTEX;
470  break;
471  }
472 
473  return orig_lock;
474 }
uint32_t options
The ao2 object option flags.
Definition: astobj2.c:70
ao2_lock_req
Which lock to request.
Definition: astobj2.h:701
#define ao2_unlock(a)
Definition: astobj2.h:730
#define ao2_wrlock(a)
Definition: astobj2.h:720
#define INTERNAL_OBJ_LOCKOBJ(user_data)
Definition: astobj2.c:160
struct ao2_rwlock_priv rwlock
Definition: astobj2.c:134
#define ast_log
Definition: astobj2.c:42
#define LOG_ERROR
Definition: logger.h:285
void * user_data[0]
Definition: astobj2.c:147
#define INTERNAL_OBJ(user_data)
Definition: astobj2.c:163
#define ao2_rdlock(a)
Definition: astobj2.h:719
#define INTERNAL_OBJ_RWLOCK(user_data)
Definition: astobj2.c:157
void * user_data[0]
Definition: astobj2.c:106
enum ao2_lock_req __adjust_lock(void *user_data, enum ao2_lock_req lock_how, int keep_stronger)
Definition: astobj2.c:425
struct __priv_data priv_data
Definition: astobj2.c:105
struct ao2_lockobj_priv lockobj
Definition: astobj2.c:145

◆ internal_is_ao2_object()

int internal_is_ao2_object ( void *  user_data)

Definition at line 193 of file astobj2.c.

References INTERNAL_OBJ, and IS_AO2_MAGIC_BAD.

194 {
195  struct astobj2 *p;
196 
197  if (!user_data) {
198  return 0;
199  }
200 
201  p = INTERNAL_OBJ(user_data);
202 
203  return !p || IS_AO2_MAGIC_BAD(p) ? 0 : 1;
204 }
#define INTERNAL_OBJ(user_data)
Definition: astobj2.c:163
#define IS_AO2_MAGIC_BAD(p)
Definition: astobj2.c:98
void * user_data[0]
Definition: astobj2.c:106

◆ log_bad_ao2()

void log_bad_ao2 ( void *  user_data,
const char *  file,
int  line,
const char *  func 
)

Definition at line 206 of file astobj2.c.

References __ast_assert_failed(), INTERNAL_OBJ, __priv_data::magic, and astobj2::priv_data.

207 {
208  struct astobj2 *p;
209  char bad_magic[100];
210 
211  if (!user_data) {
212  __ast_assert_failed(0, "user_data is NULL", file, line, func);
213  return;
214  }
215 
216  p = INTERNAL_OBJ(user_data);
217  snprintf(bad_magic, sizeof(bad_magic), "bad magic number 0x%x for object %p",
219  __ast_assert_failed(0, bad_magic, file, line, func);
220 }
void DO_CRASH_NORETURN __ast_assert_failed(int condition, const char *condition_str, const char *file, int line, const char *function)
Definition: main/utils.c:2564
#define INTERNAL_OBJ(user_data)
Definition: astobj2.c:163
void * user_data[0]
Definition: astobj2.c:106
struct __priv_data priv_data
Definition: astobj2.c:105
uint32_t magic
Definition: astobj2.c:93