Diff of /common/stats.cpp [199fc0] .. [aacde3]  Maximize  Restore

  Switch to side-by-side view

--- a/common/stats.cpp
+++ b/common/stats.cpp
@@ -1,4 +1,4 @@
-// Copyright (C) 2009 David Sugar, Tycho Softworks.
+// Copyright (C) 2009-2010 David Sugar, Tycho Softworks.
 //
 // This program is free software; you can redistribute it and/or modify
 // it under the terms of the GNU General Public License as published by
@@ -27,128 +27,128 @@
 static class __LOCAL sta : public mapped_array<stats>
 {
 public:
-	sta();
-	~sta();
+    sta();
+    ~sta();
 
-	void init(void);
+    void init(void);
 } shm;
 
 sta::sta() : mapped_array<stats>()
 {
 }
 
-sta::~sta() 
+sta::~sta()
 {
-	release();
-	remove(STAT_MAP);
+    release();
+    remove(STAT_MAP);
 }
 
-void sta::init(void) 
+void sta::init(void)
 {
-	remove(STAT_MAP);
-	create(STAT_MAP, total);
+    remove(STAT_MAP);
+    create(STAT_MAP, total);
 }
 
 stats *stats::create(void)
 {
-	shm.init();
-	base = request("system");
-	request("extension");
-	request("service");
-	request("gateway");
-	request("external");
-	request("other");
-	return base;
+    shm.init();
+    base = request("system");
+    request("extension");
+    request("service");
+    request("gateway");
+    request("external");
+    request("other");
+    return base;
 }
 
 stats *stats::request(const char *id)
 {
-	assert(id && *id);
+    assert(id && *id);
 
-	if(used >= total)
-		return NULL;
+    if(used >= total)
+        return NULL;
 
-	stats *node = shm(used++);
-	snprintf(node->id, sizeof(node->id), "%s", id);
-	return node;
+    stats *node = shm(used++);
+    snprintf(node->id, sizeof(node->id), "%s", id);
+    return node;
 }
 
 void stats::allocate(unsigned count)
 {
-	assert(count > 0);
+    assert(count > 0);
 
-	total += count;
+    total += count;
 }
 
 unsigned stats::active(void) const
 {
-	return data[0].current + data[1].current;
+    return data[0].current + data[1].current;
 }
 
 void stats::assign(stat_t entry)
 {
-	Mutex::protect(this);
-	++data[entry].period;
-	++data[entry].total;
-	++data[entry].current;
-	if(data[entry].current > data[entry].peak)
-		data[entry].peak = data[entry].current;
-	if(data[entry].current > data[entry].max)
-		data[entry].max = data[entry].current;
-	Mutex::release(this);
-	if(this != base)
-		base->assign(entry);
+    Mutex::protect(this);
+    ++data[entry].period;
+    ++data[entry].total;
+    ++data[entry].current;
+    if(data[entry].current > data[entry].peak)
+        data[entry].peak = data[entry].current;
+    if(data[entry].current > data[entry].max)
+        data[entry].max = data[entry].current;
+    Mutex::release(this);
+    if(this != base)
+        base->assign(entry);
 }
 
 void stats::release(stat_t entry)
 {
-	Mutex::protect(this);
-	if(active() == 1)
-		time(&lastcall);
-	--data[entry].current;
-	if(data[entry].current < data[entry].min)
-		data[entry].min = data[entry].current;
-	Mutex::release(this);
-	if(this != base)
-		base->release(entry);
+    Mutex::protect(this);
+    if(active() == 1)
+        time(&lastcall);
+    --data[entry].current;
+    if(data[entry].current < data[entry].min)
+        data[entry].min = data[entry].current;
+    Mutex::release(this);
+    if(this != base)
+        base->release(entry);
 }
 
 void stats::period(FILE *fp)
 {
-	unsigned pos = 0;
-	char text[80];
-	size_t len;
-	time_t last;
+    unsigned pos = 0;
+    char text[80];
+    size_t len;
+    time_t last;
 
-	while(pos < total) {
-		stats *node = shm(pos++);
-		if(!node->id[0])
-			continue;
+    while(pos < total) {
+        stats *node = shm(pos++);
+        if(!node->id[0])
+            continue;
 
-		if(fp) {
-			snprintf(text, sizeof(text), " %-12s", node->id);
-			len = strlen(text);
-		}
-		else
-			len = 0;
-		
-		Mutex::protect(node);
-		for(unsigned entry = 0; entry < 2; ++entry) {
-			if(fp) {
-				snprintf(text + len, sizeof(text) - len, " %09lu %05hu %05hu",
-				node->data[entry].period, node->data[entry].min, node->data[entry].max);
-				len = strlen(text);
-			}
-			node->data[entry].pperiod = node->data[entry].period;
-			node->data[entry].pmin = node->data[entry].min;
-			node->data[entry].pmax = node->data[entry].max;
-			node->data[entry].min = node->data[entry].max = node->data[entry].current;
-			node->data[entry].period = 0;
-		}
-		last = node->lastcall;
-		Mutex::release(node);
-		if(fp) 
-			fprintf(fp, "%s %ld\n", text, last); 
-	}
+        if(fp) {
+            snprintf(text, sizeof(text), " %-12s", node->id);
+            len = strlen(text);
+        }
+        else
+            len = 0;
+
+        Mutex::protect(node);
+        for(unsigned entry = 0; entry < 2; ++entry) {
+            if(fp) {
+                snprintf(text + len, sizeof(text) - len, " %09lu %05hu %05hu",
+                node->data[entry].period, node->data[entry].min, node->data[entry].max);
+                len = strlen(text);
+            }
+            node->data[entry].pperiod = node->data[entry].period;
+            node->data[entry].pmin = node->data[entry].min;
+            node->data[entry].pmax = node->data[entry].max;
+            node->data[entry].min = node->data[entry].max = node->data[entry].current;
+            node->data[entry].period = 0;
+        }
+        last = node->lastcall;
+        Mutex::release(node);
+        if(fp)
+            fprintf(fp, "%s %ld\n", text, last);
+    }
 }
 

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks