Commit 230f720b authored by Stephen Hemminger's avatar Stephen Hemminger Committed by David S. Miller

[IRDA]: Hashbin cleanups, remove unused code and add const where needed.

parent 055162dc
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
*/ */
#define HB_NOLOCK 0 /* No concurent access prevention */ #define HB_NOLOCK 0 /* No concurent access prevention */
#define HB_LOCK 1 /* Prevent concurent write with global lock */ #define HB_LOCK 1 /* Prevent concurent write with global lock */
#define HB_SORTED 4 /* Not yet supported */
/* /*
* Hash defines * Hash defines
...@@ -81,13 +80,13 @@ hashbin_t *hashbin_new(int type); ...@@ -81,13 +80,13 @@ hashbin_t *hashbin_new(int type);
int hashbin_delete(hashbin_t* hashbin, FREE_FUNC func); int hashbin_delete(hashbin_t* hashbin, FREE_FUNC func);
int hashbin_clear(hashbin_t* hashbin, FREE_FUNC free_func); int hashbin_clear(hashbin_t* hashbin, FREE_FUNC free_func);
void hashbin_insert(hashbin_t* hashbin, irda_queue_t* entry, long hashv, void hashbin_insert(hashbin_t* hashbin, irda_queue_t* entry, long hashv,
char* name); const char* name);
void* hashbin_remove(hashbin_t* hashbin, long hashv, char* name); void* hashbin_remove(hashbin_t* hashbin, long hashv, const char* name);
void* hashbin_remove_first(hashbin_t *hashbin); void* hashbin_remove_first(hashbin_t *hashbin);
void* hashbin_remove_this( hashbin_t* hashbin, irda_queue_t* entry); void* hashbin_remove_this( hashbin_t* hashbin, irda_queue_t* entry);
void* hashbin_find(hashbin_t* hashbin, long hashv, char* name); void* hashbin_find(hashbin_t* hashbin, long hashv, const char* name);
void* hashbin_lock_find(hashbin_t* hashbin, long hashv, char* name); void* hashbin_lock_find(hashbin_t* hashbin, long hashv, const char* name);
void* hashbin_find_next(hashbin_t* hashbin, long hashv, char* name, void* hashbin_find_next(hashbin_t* hashbin, long hashv, const char* name,
void ** pnext); void ** pnext);
irda_queue_t *hashbin_get_first(hashbin_t *hashbin); irda_queue_t *hashbin_get_first(hashbin_t *hashbin);
irda_queue_t *hashbin_get_next(hashbin_t *hashbin); irda_queue_t *hashbin_get_next(hashbin_t *hashbin);
......
...@@ -208,7 +208,7 @@ ...@@ -208,7 +208,7 @@
* This function hash the input string 'name' using the ELF hash * This function hash the input string 'name' using the ELF hash
* function for strings. * function for strings.
*/ */
static __u32 hash( char* name) static __u32 hash( const char* name)
{ {
__u32 h = 0; __u32 h = 0;
__u32 g; __u32 g;
...@@ -254,105 +254,6 @@ static void enqueue_first(irda_queue_t **queue, irda_queue_t* element) ...@@ -254,105 +254,6 @@ static void enqueue_first(irda_queue_t **queue, irda_queue_t* element)
} }
} }
#ifdef HASHBIN_UNUSED
/*
* Function enqueue_last (queue, proc)
*
* Insert item into end of queue.
*
*/
static void __enqueue_last( irda_queue_t **queue, irda_queue_t* element)
{
IRDA_DEBUG( 4, "%s()\n", __FUNCTION__);
/*
* Check if queue is empty.
*/
if ( *queue == NULL ) {
/*
* Queue is empty. Insert one element into the queue.
*/
element->q_next = element->q_prev = *queue = element;
} else {
/*
* Queue is not empty. Insert element into end of queue.
*/
element->q_prev = (*queue)->q_prev;
element->q_prev->q_next = element;
(*queue)->q_prev = element;
element->q_next = *queue;
}
}
static inline void enqueue_last( irda_queue_t **queue, irda_queue_t* element)
{
unsigned long flags;
save_flags(flags);
cli();
__enqueue_last( queue, element);
restore_flags(flags);
}
/*
* Function enqueue_queue (queue, list)
*
* Insert a queue (list) into the start of the first queue
*
*/
static void enqueue_queue( irda_queue_t** queue, irda_queue_t** list )
{
irda_queue_t* tmp;
/*
* Check if queue is empty
*/
if ( *queue ) {
(*list)->q_prev->q_next = (*queue);
(*queue)->q_prev->q_next = (*list);
tmp = (*list)->q_prev;
(*list)->q_prev = (*queue)->q_prev;
(*queue)->q_prev = tmp;
} else {
*queue = (*list);
}
(*list) = NULL;
}
/*
* Function enqueue_second (queue, proc)
*
* Insert item behind head of queue.
*
*/
static void enqueue_second(irda_queue_t **queue, irda_queue_t* element)
{
IRDA_DEBUG( 0, "enqueue_second()\n");
/*
* Check if queue is empty.
*/
if ( *queue == NULL ) {
/*
* Queue is empty. Insert one element into the queue.
*/
element->q_next = element->q_prev = *queue = element;
} else {
/*
* Queue is not empty. Insert element into ..
*/
element->q_prev = (*queue);
(*queue)->q_next->q_prev = element;
element->q_next = (*queue)->q_next;
(*queue)->q_next = element;
}
}
#endif /* HASHBIN_UNUSED */
/* /*
* Function dequeue (queue) * Function dequeue (queue)
...@@ -474,38 +375,6 @@ hashbin_t *hashbin_new(int type) ...@@ -474,38 +375,6 @@ hashbin_t *hashbin_new(int type)
return hashbin; return hashbin;
} }
#ifdef HASHBIN_UNUSED
/*
* Function hashbin_clear (hashbin, free_func)
*
* Remove all entries from the hashbin, see also the comments in
* hashbin_delete() below
*/
int hashbin_clear( hashbin_t* hashbin, FREE_FUNC free_func)
{
irda_queue_t* queue;
int i;
ASSERT(hashbin != NULL, return -1;);
ASSERT(hashbin->magic == HB_MAGIC, return -1;);
/*
* Free the entries in the hashbin
*/
for (i = 0; i < HASHBIN_SIZE; i ++ ) {
queue = dequeue_first( (irda_queue_t**) &hashbin->hb_queue[i]);
while (queue) {
if (free_func)
(*free_func)(queue);
queue = dequeue_first(
(irda_queue_t**) &hashbin->hb_queue[i]);
}
}
hashbin->hb_size = 0;
return 0;
}
#endif /* HASHBIN_UNUSED */
/* /*
* Function hashbin_delete (hashbin, free_func) * Function hashbin_delete (hashbin, free_func)
...@@ -567,7 +436,8 @@ int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func) ...@@ -567,7 +436,8 @@ int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func)
* Insert an entry into the hashbin * Insert an entry into the hashbin
* *
*/ */
void hashbin_insert(hashbin_t* hashbin, irda_queue_t* entry, long hashv, char* name) void hashbin_insert(hashbin_t* hashbin, irda_queue_t* entry, long hashv,
const char* name)
{ {
unsigned long flags = 0; unsigned long flags = 0;
int bin; int bin;
...@@ -598,14 +468,9 @@ void hashbin_insert(hashbin_t* hashbin, irda_queue_t* entry, long hashv, char* n ...@@ -598,14 +468,9 @@ void hashbin_insert(hashbin_t* hashbin, irda_queue_t* entry, long hashv, char* n
/* /*
* Insert new entry first * Insert new entry first
* TODO: Perhaps allow sorted lists?
* -> Merge sort if a sorted list should be created
*/ */
if ( hashbin->hb_type & HB_SORTED) { enqueue_first( (irda_queue_t**) &hashbin->hb_queue[ bin ],
} else { entry);
enqueue_first( (irda_queue_t**) &hashbin->hb_queue[ bin ],
entry);
}
hashbin->hb_size++; hashbin->hb_size++;
/* Release lock */ /* Release lock */
...@@ -683,7 +548,7 @@ void *hashbin_remove_first( hashbin_t *hashbin) ...@@ -683,7 +548,7 @@ void *hashbin_remove_first( hashbin_t *hashbin)
* In other case, you must think hard to guarantee unicity of the index. * In other case, you must think hard to guarantee unicity of the index.
* Jean II * Jean II
*/ */
void* hashbin_remove( hashbin_t* hashbin, long hashv, char* name) void* hashbin_remove( hashbin_t* hashbin, long hashv, const char* name)
{ {
int bin, found = FALSE; int bin, found = FALSE;
unsigned long flags = 0; unsigned long flags = 0;
...@@ -834,7 +699,7 @@ void* hashbin_remove_this( hashbin_t* hashbin, irda_queue_t* entry) ...@@ -834,7 +699,7 @@ void* hashbin_remove_this( hashbin_t* hashbin, irda_queue_t* entry)
* Find item with the given hashv or name * Find item with the given hashv or name
* *
*/ */
void* hashbin_find( hashbin_t* hashbin, long hashv, char* name ) void* hashbin_find( hashbin_t* hashbin, long hashv, const char* name )
{ {
int bin; int bin;
irda_queue_t* entry; irda_queue_t* entry;
...@@ -888,7 +753,7 @@ void* hashbin_find( hashbin_t* hashbin, long hashv, char* name ) ...@@ -888,7 +753,7 @@ void* hashbin_find( hashbin_t* hashbin, long hashv, char* name )
* I call it safe, but it's only safe with respect to the hashbin, not its * I call it safe, but it's only safe with respect to the hashbin, not its
* content. - Jean II * content. - Jean II
*/ */
void* hashbin_lock_find( hashbin_t* hashbin, long hashv, char* name ) void* hashbin_lock_find( hashbin_t* hashbin, long hashv, const char* name )
{ {
unsigned long flags = 0; unsigned long flags = 0;
irda_queue_t* entry; irda_queue_t* entry;
...@@ -917,7 +782,7 @@ void* hashbin_lock_find( hashbin_t* hashbin, long hashv, char* name ) ...@@ -917,7 +782,7 @@ void* hashbin_lock_find( hashbin_t* hashbin, long hashv, char* name )
* context of the search. On the other hand, it might fail and return * context of the search. On the other hand, it might fail and return
* NULL if the entry is removed. - Jean II * NULL if the entry is removed. - Jean II
*/ */
void* hashbin_find_next( hashbin_t* hashbin, long hashv, char* name, void* hashbin_find_next( hashbin_t* hashbin, long hashv, const char* name,
void ** pnext) void ** pnext)
{ {
unsigned long flags = 0; unsigned long flags = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment