On Mon, Jan 13, 2014 at 03:24:28PM -0800, Ethan Jackson wrote:
> As discussed off list I'd like a comment explaining why we need the
> free list.  Other than that:
> 
> Acked-by: Ethan Jackson <et...@nicira.com>

Thanks.  I added that and several other comments.

diff --git a/lib/ovs-thread.c b/lib/ovs-thread.c
index 6e6af98..f532070 100644
--- a/lib/ovs-thread.c
+++ b/lib/ovs-thread.c
@@ -475,27 +475,44 @@ count_cpu_cores(void)
 #define L2_SIZE 1024
 #define MAX_KEYS (L1_SIZE * L2_SIZE)
 
+/* A piece of thread-specific data. */
 struct ovsthread_key {
-    struct list list_node;
+    struct list list_node;      /* In 'inuse_keys' or 'free_keys'. */
+    void (*destructor)(void *); /* Called at thread exit. */
+
+    /* Indexes into the per-thread array in struct ovsthread_key_slots.
+     * This key's data is stored in p1[index / L2_SIZE][index % L2_SIZE]. */
     unsigned int index;
-    void (*destructor)(void *);
 };
 
+/* Per-thread data structure. */
 struct ovsthread_key_slots {
-    struct list list_node;
+    struct list list_node;      /* In 'slots_list'. */
     void **p1[L1_SIZE];
 };
 
+/* Contains "struct ovsthread_key_slots *". */
 static pthread_key_t tsd_key;
 
+/* Guards data structures below. */
 static struct ovs_mutex key_mutex = OVS_MUTEX_INITIALIZER;
 
+/* 'inuse_keys' holds "struct ovsthread_key"s that have been created and not
+ * yet destroyed.
+ *
+ * 'free_keys' holds "struct ovsthread_key"s that have been deleted and are
+ * ready for reuse.  (We keep them around only to be able to easily locate
+ * free indexes.)
+ *
+ * Together, 'inuse_keys' and 'free_keys' hold an ovsthread_key for every index
+ * from 0 to n_keys - 1, inclusive. */
 static struct list inuse_keys OVS_GUARDED_BY(key_mutex)
     = LIST_INITIALIZER(&inuse_keys);
 static struct list free_keys OVS_GUARDED_BY(key_mutex)
     = LIST_INITIALIZER(&free_keys);
 static unsigned int n_keys OVS_GUARDED_BY(key_mutex);
 
+/* All existing struct ovsthread_key_slots. */
 static struct list slots_list OVS_GUARDED_BY(key_mutex)
     = LIST_INITIALIZER(&slots_list);
 
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to