[asterisk-commits] russell: branch russell/frame_caching r41228 -
/team/russell/frame_caching/main/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Sun Aug 27 08:48:04 MST 2006
Author: russell
Date: Sun Aug 27 10:48:03 2006
New Revision: 41228
URL: http://svn.digium.com/view/asterisk?rev=41228&view=rev
Log:
force profiles to be thread safe
Modified:
team/russell/frame_caching/main/asterisk.c
Modified: team/russell/frame_caching/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/russell/frame_caching/main/asterisk.c?rev=41228&r1=41227&r2=41228&view=diff
==============================================================================
--- team/russell/frame_caching/main/asterisk.c (original)
+++ team/russell/frame_caching/main/asterisk.c Sun Aug 27 10:48:03 2006
@@ -347,6 +347,7 @@
int64_t mark;
int64_t value;
int64_t events;
+ ast_mutex_t lock;
};
struct profile_data {
@@ -366,18 +367,24 @@
int n = 10; /* default entries */
if (prof_data == NULL) {
+ int x;
prof_data = ast_calloc(1, l + n*sizeof(struct profile_entry));
if (prof_data == NULL)
return -1;
prof_data->entries = 0;
prof_data->max_size = n;
+ for (x = 0; x < n; x++)
+ ast_mutex_init(&prof_data->e[n].lock);
}
if (prof_data->entries >= prof_data->max_size) {
void *p;
+ int x;
n = prof_data->max_size + 20;
p = ast_realloc(prof_data, l + n*sizeof(struct profile_entry));
if (p == NULL)
return -1;
+ for (x = prof_data->max_size; x < n; x++)
+ ast_mutex_init(&prof_data->e[n].lock);
prof_data = p;
prof_data->max_size = n;
}
@@ -426,6 +433,7 @@
{
if (!prof_data || i < 0 || i > prof_data->entries) /* invalid index */
return 0;
+ ast_mutex_lock(&prof_data->e[i].lock);
if (startstop == 1)
prof_data->e[i].mark = rdtsc();
else {
@@ -435,6 +443,7 @@
prof_data->e[i].value += prof_data->e[i].mark;
prof_data->e[i].events++;
}
+ ast_mutex_unlock(&prof_data->e[i].lock);
return prof_data->e[i].mark;
}
More information about the asterisk-commits
mailing list