aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2020-04-18 10:32:45 +0300
committerSergey Poznyakoff <gray@gnu.org>2020-04-18 10:32:45 +0300
commit1c754c175e78d36aec8c4437d5a024169445f798 (patch)
treea0627bb6a6a6ab3e4249e41b009b7cd9c4d16735
parent7673f245e3ea59d912b382ee9232bf5fbeb562f1 (diff)
downloadwydawca-1c754c175e78d36aec8c4437d5a024169445f798.tar.gz
wydawca-1c754c175e78d36aec8c4437d5a024169445f798.tar.bz2
Minor fixes.
* src/timer.c (struct timer_slot): New member: state. (timer_start,timer_stop): Keep track of the timer state. * src/triplet.c: Remove unneeded function.
-rw-r--r--src/timer.c27
-rw-r--r--src/triplet.c12
2 files changed, 19 insertions, 20 deletions
diff --git a/src/timer.c b/src/timer.c
index f5d7c93..268b096 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -23,6 +23,7 @@
struct timer_slot {
char *name;
+ enum { STOPPED, RUNNING } state;
double real;
double self_user; /* user time in sec */
double self_system; /* system time in sec */
@@ -66,23 +67,30 @@ make_key(void)
pthread_key_create(&key, timer_free);
}
-/* Lookup a timer by its name. If it does not exist, create it. */
-wydawca_timer_t
-timer_get(const char *name)
+struct grecs_symtab *
+get_thread_timer_table(void)
{
- struct timer_slot slot, *ret;
- int install = 1;
struct grecs_symtab *timer_table;
pthread_once(&key_once, make_key);
if ((timer_table = pthread_getspecific(key)) == NULL) {
- timer_table = grecs_symtab_create(sizeof(slot),
+ timer_table = grecs_symtab_create(sizeof(struct timer_slot),
timer_hasher,
NULL, NULL, NULL, NULL);
if (!timer_table)
grecs_alloc_die();
pthread_setspecific(key, timer_table);
}
+ return timer_table;
+}
+
+/* Lookup a timer by its name. If it does not exist, create it. */
+wydawca_timer_t
+timer_get(const char *name)
+{
+ struct timer_slot slot, *ret;
+ int install = 1;
+ struct grecs_symtab *timer_table = get_thread_timer_table();
slot.name = (char *)name;
ret = grecs_symtab_lookup_or_install(timer_table, &slot, &install);
@@ -99,6 +107,7 @@ timer_start(const char *name)
gettimeofday(&t->real_mark, NULL);
getrusage(RUSAGE_SELF, &t->self_mark);
getrusage(RUSAGE_CHILDREN, &t->children_mark);
+ t->state = RUNNING;
return t;
}
@@ -129,7 +138,10 @@ wydawca_timer_t
timer_stop(const char *name)
{
wydawca_timer_t t = timer_get(name);
- _timer_compute(t);
+ if (t->state == RUNNING) {
+ _timer_compute(t);
+ t->state = STOPPED;
+ }
return t;
}
@@ -193,4 +205,3 @@ timer_format_time(double t)
grecs_alloc_die();
return str;
}
-
diff --git a/src/triplet.c b/src/triplet.c
index a82ac88..d9e503f 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -540,18 +540,6 @@ wy_get_stat_array(void)
return stat;
}
-WY_STAT_COUNTER *
-wy_get_stat_ptr(int what)
-{
- WY_STAT_COUNTER *stat;
- pthread_once(&key_once, make_key);
- if ((stat = pthread_getspecific(key)) == NULL) {
- stat = grecs_calloc(WY_MAX_STAT, sizeof(stat[0]));
- pthread_setspecific(key, stat);
- }
- return stat + what;
-}
-
void *
wy_thr_triplet(void *ptr)
{

Return to:

Send suggestions and report system problems to the System administrator.