193 struct timespec timeout = { 0, };
198 ast_log(
LOG_ERROR,
"%sLOCK has no datastore and func_lock is unloading, failing.\n",
199 trylock ?
"TRY" :
"");
205 ast_log(
LOG_ERROR,
"Unable to allocate new datastore. No locks will be obtained.\n");
212 "Unable to allocate datastore list head. %sLOCK will fail.\n",
213 trylock ?
"TRY" :
"");
218 lock_store->
data = list;
225 list = lock_store->
data;
230 if (strcmp(current->
name, lockname) == 0) {
238 "Lock doesn't exist whilst unloading. %sLOCK will fail.\n",
239 trylock ?
"TRY" :
"");
246 current =
ast_calloc(1,
sizeof(*current) + strlen(lockname) + 1);
252 strcpy(current->
name, lockname);
260 ast_log(
LOG_ERROR,
"Unable to initialize condition variable: %s\n", strerror(res));
285 "Busy unloading. %sLOCK will fail.\n",
286 trylock ?
"TRY" :
"");
295 if (!(clframe =
ast_calloc(1,
sizeof(*clframe)))) {
297 "Unable to allocate channel lock frame. %sLOCK will fail.\n",
298 trylock ?
"TRY" :
"");
316 if (current->
owner == chan) {
327 timeout.tv_sec = now.tv_sec + 3;
328 timeout.tv_nsec = now.tv_usec * 1000;
333 while (!trylock && !res && current->
owner) {
336 if (current->
owner) {
345 current->
owner = chan;
376 ast_debug(1,
"This should NEVER happen\n");
440 e->
command =
"dialplan locks show";
442 "Usage: dialplan locks show\n" 443 " List all locks known to func_lock, along with their current status.\n";
450 ast_cli(a->
fd,
"%-40s Requesters Owner\n",
"Name");
460 ast_cli(a->
fd,
"%d total locks listed.\n", c);
static char * handle_cli_locks_show(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
Main Channel structure associated with a channel.
#define AST_CLI_DEFINE(fn, txt,...)
#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 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
int ast_cli_unregister(struct ast_cli_entry *e)
Unregisters a command or an array of commands.
descriptor for a cli entry.
#define AST_LIST_UNLOCK(head)
Attempts to unlock a list.
struct lock_frame::@210 entries
static struct ast_custom_function trylock_function
Structure for a data store type.
#define ast_cond_wait(cond, mutex)
#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.
void ast_cli(int fd, const char *fmt,...)
#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.
#define ast_module_unref(mod)
Release a reference to the module.
pthread_cond_t ast_cond_t
#define AST_LIST_HEAD_DESTROY(head)
Destroys a list head structure.
#define ast_cli_register(e)
Registers a command or an array of commands.
static int trylock_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
#define ast_custom_function_register_escalating(acf, escalation)
Register a custom function which requires escalated privileges.
#define ast_debug(level,...)
Log a DEBUG message.
General Asterisk PBX channel definitions.
Data structure associated with a custom dialplan function.
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.
static const struct ast_datastore_info lock_info
#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)
#define ast_cond_destroy(cond)
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_HEAD_INIT(head)
Initializes a list head structure.
#define ast_calloc(num, len)
A wrapper for calloc()
static void lock_fixup(void *data, struct ast_channel *oldchan, struct ast_channel *newchan)
static struct ast_cli_entry cli_locks_show
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
Standard Command Line Interface.
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
struct ast_channel * owner
const char * ast_channel_name(const struct ast_channel *chan)
struct ast_channel * channel
static int lock_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
#define ast_datastore_alloc(info, uid)
#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.
static int unload_module(void)
#define ast_cond_timedwait(cond, mutex, time)
static struct ast_custom_function lock_function
Structure for mutex and tracking information.
struct channel_lock_frame::@211 list
#define ast_mutex_unlock(a)
#define ast_module_ref(mod)
Hold a reference to the module.