+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
+ return ts.tv_sec;
+}
+
+/* lock the set of sessions for exclusive access */
+static inline void sessionset_lock()
+{
+ pthread_mutex_lock(&sessions.mutex);
+}
+
+/* unlock the set of sessions of exclusive access */
+static inline void sessionset_unlock()
+{
+ pthread_mutex_unlock(&sessions.mutex);
+}
+
+/*
+ * search within the set of sessions the session of 'uuid'.
+ * 'hashidx' is the precomputed hash for 'uuid'
+ * return the session or NULL
+ */
+static struct afb_session *sessionset_search(const char *uuid, uint8_t hashidx)
+{
+ struct afb_session *session;
+
+ session = sessions.heads[hashidx];
+ while (session && strcmp(uuid, session->uuid))
+ session = session->next;
+
+ return session;
+}
+
+/* add 'session' to the set of sessions */
+static int sessionset_add(struct afb_session *session, uint8_t hashidx)
+{
+ /* check availability */
+ if (sessions.max && sessions.count >= sessions.max) {
+ errno = EBUSY;
+ return -1;
+ }
+
+ /* add the session */
+ session->next = sessions.heads[hashidx];
+ sessions.heads[hashidx] = session;
+ sessions.count++;
+ return 0;