147 struct channel_lock_frame *clframe;
166 struct channel_lock_frame *clframe = NULL;
187 struct timespec forever = { 1000000, 0 };
189 int found_requester = 0;
192 pthread_testcancel();
207 pthread_testcancel();
210 if (!found_requester) {
211 nanosleep(&forever, NULL);
229 return strcasecmp(chan->
name, cmp_args->name) ? 0 :
CMP_MATCH;
236 struct channel_lock_frame *clframe = NULL;
239 struct timespec timeout = { 0, };
243 ast_debug(1,
"Channel %s has no lock datastore, so we're allocating one.\n", chan->
name);
246 ast_log(
LOG_ERROR,
"Unable to allocate new datastore. No locks will be obtained.\n");
253 "Unable to allocate datastore list head. %sLOCK will fail.\n",
254 trylock ?
"TRY" :
"");
259 lock_store->
data = list;
263 list = lock_store->
data;
268 if (strcmp(current->
name, lockname) == 0) {
281 current =
ast_calloc(1,
sizeof(*current) + strlen(lockname) + 1);
287 strcpy(current->
name, lockname);
295 ast_log(
LOG_ERROR,
"Unable to initialize condition variable: %s\n", strerror(res));
327 if (!(clframe =
ast_calloc(1,
sizeof(*clframe)))) {
329 "Unable to allocate channel lock frame. %sLOCK will fail.\n",
330 trylock ?
"TRY" :
"");
345 if (current->
owner == chan) {
365 pthread_kill(broker_tid, SIGURG);
370 timeout.tv_sec = now.tv_sec + 3;
371 timeout.tv_nsec = now.tv_usec * 1000;
377 current->
owner = chan;
392 struct channel_lock_frame *clframe;
407 ast_debug(1,
"This should NEVER happen\n");
508 pthread_cancel(broker_tid);
509 pthread_kill(broker_tid, SIGURG);
510 pthread_join(broker_tid, NULL);
525 ast_log(
LOG_ERROR,
"Failed to start lock broker thread. Unloading func_lock module.\n");
Main Channel structure associated with a channel.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
#define AST_LIST_LOCK(head)
Locks a list.
static int load_module(void)
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
#define ao2_link(arg1, arg2)
int ao2_container_count(struct ao2_container *c)
Returns the number of elements in a container.
#define AST_LIST_HEAD(name, type)
Defines a structure to be used to hold a list of specified type.
int ast_autoservice_start(struct ast_channel *chan)
Automatically service a channel for us...
struct lock_frame * lock_frame
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
static struct ast_custom_function trylock_function
Structure for a data store type.
struct ao2_container * requesters
#define ast_cond_init(cond, attr)
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
#define ast_mutex_lock(a)
Structure for a data store object.
struct ast_datastore * ast_channel_datastore_find(struct ast_channel *chan, const struct ast_datastore_info *info, const char *uid)
Find a datastore on a channel.
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
struct channel_lock_frame::@135 list
#define ast_cond_signal(cond)
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
int ast_datastore_free(struct ast_datastore *datastore)
Free a data store object.
pthread_cond_t ast_cond_t
#define AST_LIST_HEAD_DESTROY(head)
Destroys a list head structure.
static int trylock_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
#define ast_pthread_create_background(a, b, c, d)
static int ast_channel_hash_cb(const void *obj, const int flags)
#define ast_custom_function_register_escalating(acf, escalation)
Register a custom function which requires escalated privileges.
static void * lock_broker(void *unused)
#define ast_debug(level,...)
Log a DEBUG message.
General Asterisk PBX channel definitions.
#define AST_PTHREADT_NULL
Data structure associated with a custom dialplan function.
#define ao2_ref(o, delta)
A set of macros to manage forward-linked lists.
#define AST_LIST_REMOVE_HEAD(head, field)
Removes and returns the head entry from a list.
Core PBX routines and definitions.
int ast_autoservice_stop(struct ast_channel *chan)
Stop servicing a channel for us...
#define AST_LIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a list of specified type, statically initialized.
#define AST_LIST_INSERT_TAIL(head, elm, field)
Appends a list entry to the tail of a list.
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int get_lock(struct ast_channel *chan, char *lockname, int trylock)
const ast_string_field name
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
#define ast_cond_destroy(cond)
struct ast_datastore * ast_datastore_alloc(const struct ast_datastore_info *info, const char *uid)
static void lock_free(void *data)
#define AST_LIST_TRAVERSE(head, var, field)
Loops over (traverses) the entries in a list.
#define AST_LIST_ENTRY(type)
Declare a forward link structure inside a list entry.
#define AST_LIST_INSERT_HEAD(head, elm, field)
Inserts a list entry at the head of a list.
#define AST_LIST_HEAD_INIT(head)
Initializes a list head structure.
static void lock_fixup(void *data, struct ast_channel *oldchan, struct ast_channel *newchan)
static int unlock_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static struct ast_custom_function unlock_function
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
#define ao2_container_alloc(arg1, arg2, arg3)
struct ast_channel * owner
struct ast_channel * channel
static int lock_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
static struct ast_datastore_info lock_info
#define ast_mutex_init(pmutex)
#define ast_mutex_destroy(a)
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
int ast_channel_datastore_add(struct ast_channel *chan, struct ast_datastore *datastore)
Add a datastore to a channel.
struct lock_frame::@134 entries
static int unload_module(void)
#define ao2_unlink(arg1, arg2)
#define ast_cond_timedwait(cond, mutex, time)
static struct ast_custom_function lock_function
Structure for mutex and tracking information.
static force_inline int attribute_pure ast_str_case_hash(const char *str)
Compute a hash value on a case-insensitive string.
static int ast_channel_cmp_cb(void *obj, void *arg, int flags)
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
static pthread_t broker_tid
#define ast_mutex_unlock(a)