commit:22ea1c1c4327635ca2ac9a7e2b7b074bd03201ba
author:Chip Black
committer:Chip Black
date:Fri Jul 25 18:13:58 2014 -0500
parents:2ed464c9a551f74387dd8a719df6a0fe3760ab10
Add touch method to update stringring timestamp
diff --git a/common/stringring.c b/common/stringring.c
line changes: +15/-0
index 5f7101a..7784e1b
--- a/common/stringring.c
+++ b/common/stringring.c
@@ -152,6 +152,21 @@ int stringring_remove_index(struct stringring *sr, int idx) {
 	return ret;
 }
 
+int stringring_touch(struct stringring *sr, const char *data) {
+	STRINGRING_DATA_CHECK();
+	int ret, idx;
+
+	flock(sr->fd, LOCK_EX);
+	idx = stringring_find_unlocked(sr, data, 0);
+	ret = idx >= 0;
+	if (ret) {
+		sr->sb->entries[idx].timestamp = time(NULL);
+	}
+	flock(sr->fd, LOCK_UN);
+
+	return ret;
+}
+
 int stringring_remove(struct stringring *sr, const char *data) {
 	STRINGRING_DATA_CHECK();
 	int ret;

diff --git a/common/stringring.h b/common/stringring.h
line changes: +1/-0
index c742e25..ac931f4
--- a/common/stringring.h
+++ b/common/stringring.h
@@ -25,6 +25,7 @@ void stringring_close(struct stringring *sr);
 int stringring_add(struct stringring *sr, const char *data);
 int stringring_find(struct stringring *sr, const char *data, unsigned int max_age);
 int stringring_remove(struct stringring *sr, const char *data);
+int stringring_touch(struct stringring *sr, const char *data);
 int stringring_clear(struct stringring *sr);
 
 #endif /* _STRINGRING_H */