Changeset 5707

Use a rwlock to protect the dialplan data structures rather than a simple mutex

Comitted by:  mjagdis
Date:  Jun 04 2010 * 23:10 (about 1 year ago)

Affected files:

callweaver/trunk/corelib/callweaver.c (unified diff)

r5697r5707
152152 #include "console.h"
153153
154154
155 /* From corelib/pbx.c */
156 extern pthread_rwlock_t conlock;
157
158
155159 #if defined(_POSIX_TIMERS)
156160 # if defined(_POSIX_MONOTONIC_CLOCK) && defined(__USE_XOPEN2K)
157161 clockid_t global_clock_monotonic = CLOCK_MONOTONIC;
------
17511755 if ((option_console || option_nofork) && !option_verbose)
17521756 cw_verbose("[ Initializing Custom Configuration Options ]");
17531757
1758 pthread_rwlock_init(&conlock, NULL);
1759
17541760 cw_registry_init(&atexit_registry, 1);
17551761 cw_registry_init(&channel_registry, 1024);
17561762 cw_registry_init(&device_registry, 1024);

callweaver/trunk/corelib/pbx.c (unified diff)

r5700r5707
166166 CW_MUTEX_DEFINE_STATIC(maxcalllock);
167167 static int countcalls = 0;
168168
169 pthread_rwlock_t conlock;
169170 static struct cw_context *contexts = NULL;
170 CW_MUTEX_DEFINE_STATIC(conlock); /* Lock for the cw_context list */
171171
172172 CW_MUTEX_DEFINE_STATIC(hintlock); /* Lock for extension state notifys */
173173 static int stateid = 1;
------
466466
467467 struct cw_context *cw_context_find(const char *name)
468468 {
469 struct cw_context *tmp;
470 unsigned int hash;
469 struct cw_context *tmp;
470 unsigned int hash;
471471
472 cw_mutex_lock(&conlock);
473 if (name)
474 {
475 hash = cw_hash_string(name);
476 for (tmp = contexts; tmp; tmp = tmp->next)
477 if (hash == tmp->hash && !strcmp(name, tmp->name))
478 break;
479 }
480 else
481 {
482 tmp = contexts;
483 }
484 cw_mutex_unlock(&conlock);
485 return tmp;
472 if (name) {
473 pthread_rwlock_rdlock(&conlock);
474
475 hash = cw_hash_string(name);
476 for (tmp = contexts; tmp; tmp = tmp->next)
477 if (hash == tmp->hash && !strcmp(name, tmp->name))
478 break;
479
480 pthread_rwlock_unlock(&conlock);
481 } else
482 tmp = contexts;
483
484 return tmp;
486485 }
487486
488487 #define STATUS_NO_CONTEXT 1
------
756755
757756 int pbx_retrieve_substr(struct cw_channel *chan, struct cw_registry *vars, char *src, size_t srclen, struct cw_dynstr *result)
758757 {
759 struct cw_dynargs av = CW_DYNARRAY_INIT;
758 struct cw_dynargs av;
760759 char *args;
761760 size_t i;
762761 int offset, length;
------
790789
791790 while (i && isspace(src[i])) i--;
792791
792 cw_dynargs_init(&av, 1, 1);
793793 args = NULL;
794794 if (!cw_split_args(&av, src, "\0", '(', &args)) {
795795 if (args) {
------
857857 } else
858858 result->error = 1;
859859
860 cw_dynargs_free(&av);
860861 return res;
861862 }
862863
------
11111112 int stacklen = 0;
11121113 int res = -1;
11131114
1114 cw_mutex_lock(&conlock);
1115 pthread_rwlock_rdlock(&conlock);
11151116
11161117 e = pbx_find_extension(c, con, context, exten, priority, label, callerid, action, incstack, &stacklen, &status, &sw, &data, &foundcontext);
11171118
------
11251126 case HELPER_CANMATCH:
11261127 case HELPER_EXISTS:
11271128 case HELPER_MATCHMORE:
1128 cw_mutex_unlock(&conlock);
1129 pthread_rwlock_unlock(&conlock);
11291130 break;
11301131 case HELPER_EXEC:
1131 cw_mutex_unlock(&conlock);
1132 pthread_rwlock_unlock(&conlock);
11321133 if (c->context != context)
11331134 cw_copy_string(c->context, context, sizeof(c->context));
11341135 if (c->exten != exten)
------
11651166 case HELPER_EXISTS:
11661167 case HELPER_MATCHMORE:
11671168 case HELPER_FINDLABEL:
1168 cw_mutex_unlock(&conlock);
1169 pthread_rwlock_unlock(&conlock);
11691170 break;
11701171 case HELPER_EXEC:
1171 cw_mutex_unlock(&conlock);
1172 pthread_rwlock_unlock(&conlock);
11721173 if (sw->exec)
11731174 res = sw->exec(c, (foundcontext ? foundcontext : context), exten, priority, callerid, data.data);
11741175 else
------
11811182 }
11821183 else
11831184 {
1184 cw_mutex_unlock(&conlock);
1185 pthread_rwlock_unlock(&conlock);
11851186 switch (status)
11861187 {
11871188 case STATUS_NO_CONTEXT:
------
12261227 char *incstack[CW_PBX_MAX_STACK];
12271228 int stacklen = 0;
12281229
1229 cw_mutex_lock(&conlock);
1230 pthread_rwlock_rdlock(&conlock);
12301231
12311232 e = pbx_find_extension(c, NULL, context, exten, PRIORITY_HINT, NULL, "", HELPER_EXISTS, incstack, &stacklen, &status, &sw, &data, &foundcontext);
12321233
1233 cw_mutex_unlock(&conlock);
1234 pthread_rwlock_rdlock(&conlock);
12341235
12351236 cw_dynstr_free(&data);
12361237
------
28752876
28762877 length = sizeof(struct cw_context);
28772878 length += strlen(name) + 1;
2879
28782880 if (!extcontexts)
28792881 {
28802882 local_contexts = &contexts;
2881 cw_mutex_lock(&conlock);
2883 pthread_rwlock_wrlock(&conlock);
28822884 }
28832885 else
28842886 {
------
28902892 if (hash == tmp->hash && !strcmp(name, tmp->name))
28912893 {
28922894 if (!extcontexts)
2893 cw_mutex_unlock(&conlock);
2895 pthread_rwlock_unlock(&conlock);
28942896 cw_log(CW_LOG_WARNING, "Failed to register context '%s' because it is already in use\n", name);
28952897 return NULL;
28962898 }
------
29192921 }
29202922
29212923 if (!extcontexts)
2922 cw_mutex_unlock(&conlock);
2924 pthread_rwlock_unlock(&conlock);
29232925 return tmp;
29242926 }
29252927
------
46194621 struct cw_exten *e, *el, *en;
46204622 struct cw_ignorepat *ipi, *ipl = NULL;
46214623
4622 cw_mutex_lock(&conlock);
4624 pthread_rwlock_wrlock(&conlock);
46234625 tmp = contexts;
46244626 while (tmp)
46254627 {
------
46854687 tmpil = NULL;
46864688 continue;
46874689 }
4688 cw_mutex_unlock(&conlock);
4690 pthread_rwlock_unlock(&conlock);
46894691 return;
46904692 }
46914693 tmpl = tmp;
46924694 tmp = tmp->next;
46934695 }
4694 cw_mutex_unlock(&conlock);
4696 pthread_rwlock_unlock(&conlock);
46954697 }
46964698
46974699
------
47314733 cw_mutex_unlock(&hintlock);
47324734
47334735 tmp = *extcontexts;
4734 cw_mutex_lock(&conlock);
47354736 if (registrar)
47364737 {
47374738 cw_context_destroy(NULL,registrar);
------
47524753 }
47534754 if (lasttmp)
47544755 {
4756 pthread_rwlock_wrlock(&conlock);
47554757 lasttmp->next = contexts;
47564758 contexts = *extcontexts;
4759 pthread_rwlock_unlock(&conlock);
47574760 *extcontexts = NULL;
47584761 }
47594762 else
47604763 {
47614764 cw_log(CW_LOG_WARNING, "Requested contexts could not be merged\n");
47624765 }
4763 cw_mutex_unlock(&conlock);
47644766
47654767 /* restore the watchers for hints that can be found; notify those that
47664768 cannot be restored
------
49214923 */
49224924 int cw_lock_contexts()
49234925 {
4924 return cw_mutex_lock(&conlock);
4926 return pthread_rwlock_rdlock(&conlock);
49254927 }
49264928
49274929 int cw_unlock_contexts()
49284930 {
4929 return cw_mutex_unlock(&conlock);
4931 return pthread_rwlock_unlock(&conlock);
49304932 }
49314933
49324934 /*