1 /*********************************************************************
5 * Description: General queue implementation
6 * Status: Experimental.
7 * Author: Dag Brattli <dagb@cs.uit.no>
8 * Created at: Tue Jun 9 13:26:50 1998
9 * Modified at: Thu Jul 1 10:18:21 1999
10 * Modified by: Dag Brattli <dagb@cs.uit.no>
12 * Copyright (C) 1998-1999, Aage Kvalnes <aage@cs.uit.no>
13 * Copyright (c) 1998, Dag Brattli
14 * All Rights Reserved.
16 * This code is taken from the Vortex Operating System written by Aage
17 * Kvalnes and has been ported to Linux and Linux/IR by Dag Brattli
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License as
21 * published by the Free Software Foundation; either version 2 of
22 * the License, or (at your option) any later version.
24 * Neither Dag Brattli nor University of Tromsø admit liability nor
25 * provide warranty for any of this software. This material is
26 * provided "AS-IS" and at no charge.
28 ********************************************************************/
30 #include <linux/types.h>
31 #include <linux/spinlock.h>
49 #define HASHBIN_SIZE 8
50 #define HASHBIN_MASK 0x7
53 #define ALIGN __attribute__((aligned))
56 typedef void (*FREE_FUNC
)( void *arg
);
61 #define GET_HASHBIN(x) ( x & HASHBIN_MASK )
63 #define QUEUE struct queue_t
68 char q_name
[ NAME_SIZE
];
72 typedef struct hashbin_t
{
76 spinlock_t hb_mutex
[ HASHBIN_SIZE
] ALIGN
;
77 QUEUE
* hb_queue
[ HASHBIN_SIZE
] ALIGN
;
82 hashbin_t
*hashbin_new(int type
);
83 int hashbin_delete(hashbin_t
* hashbin
, FREE_FUNC func
);
84 int hashbin_clear(hashbin_t
* hashbin
, FREE_FUNC free_func
);
85 void hashbin_insert(hashbin_t
* hashbin
, QUEUE
* entry
, __u32 hashv
,
87 void* hashbin_find(hashbin_t
* hashbin
, __u32 hashv
, char* name
);
88 void* hashbin_remove(hashbin_t
* hashbin
, __u32 hashv
, char* name
);
89 void* hashbin_remove_first(hashbin_t
*hashbin
);
90 QUEUE
*hashbin_get_first(hashbin_t
*hashbin
);
91 QUEUE
*hashbin_get_next(hashbin_t
*hashbin
);
93 void enqueue_last(QUEUE
**queue
, QUEUE
* element
);
94 void enqueue_first(QUEUE
**queue
, QUEUE
* element
);
95 QUEUE
*dequeue_first(QUEUE
**queue
);
98 * Function hashbin_get_size (hashbin)
100 * Returns the number of elements in the hashbin
103 extern __inline__
int hashbin_get_size(hashbin_t
* hashbin
)
105 return hashbin
->hb_size
;