summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/fd.h
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2009-06-15 13:05:39 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-06-15 23:44:36 -0700
commitefcce990960fb91d422630fc7b310b216a500fed (patch)
tree7c417d43464c26476d9dfd541c13c2bf05f9b2bf /libglusterfs/src/fd.h
parent7006ae207c9e8ab9685d8e2e7455bd4e3b217c97 (diff)
libglusterfs: Turn fd-table O(1)
This commit reduces CPU usage of gf_fd_unused_get drastically by making it O(1) instead of O(n). Related to: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=16 Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'libglusterfs/src/fd.h')
-rw-r--r--libglusterfs/src/fd.h20
1 files changed, 18 insertions, 2 deletions
diff --git a/libglusterfs/src/fd.h b/libglusterfs/src/fd.h
index d3c9afde3f9..b4bb1211847 100644
--- a/libglusterfs/src/fd.h
+++ b/libglusterfs/src/fd.h
@@ -51,14 +51,30 @@ struct _fd {
};
typedef struct _fd fd_t;
+struct fd_table_entry {
+ fd_t *fd;
+ int next_free;
+};
+typedef struct fd_table_entry fdentry_t;
+
struct _fdtable {
int refcount;
uint32_t max_fds;
pthread_mutex_t lock;
- fd_t **fds;
+ fdentry_t *fdentries;
+ int first_free;
};
typedef struct _fdtable fdtable_t;
+/* Signifies no more entries in the fd table. */
+#define GF_FDTABLE_END -1
+
+/* The value us the same as GF_FDTABLE_END but the
+ * purpose is different here. This is used to invalidated
+ * the next_free value in an fdentry that has been allocated
+ */
+#define GF_FDENTRY_ALLOCATED -1
+
#include "logging.h"
#include "xlator.h"
@@ -77,7 +93,7 @@ gf_fd_unused_get (fdtable_t *fdtable, fd_t *fdptr);
int32_t
gf_fd_unused_get2 (fdtable_t *fdtable, fd_t *fdptr, int32_t fd);
-fd_t **
+fdentry_t *
gf_fd_fdtable_get_all_fds (fdtable_t *fdtable, uint32_t *count);
void