Add touch method to update stringring timestamp
authorChip Black <bytex64@bytex64.net>
Fri, 25 Jul 2014 23:13:58 +0000 (18:13 -0500)
committerChip Black <bytex64@bytex64.net>
Fri, 25 Jul 2014 23:13:58 +0000 (18:13 -0500)
common/stringring.c
common/stringring.h

index 5f7101a..7784e1b 100644 (file)
@@ -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;
index c742e25..ac931f4 100644 (file)
@@ -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 */