Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

irqueue.h

Go to the documentation of this file.
00001 /*********************************************************************
00002  *                
00003  * Filename:      irqueue.h
00004  * Version:       0.3
00005  * Description:   General queue implementation
00006  * Status:        Experimental.
00007  * Author:        Dag Brattli <dagb@cs.uit.no>
00008  * Created at:    Tue Jun  9 13:26:50 1998
00009  * Modified at:   Thu Oct  7 13:25:16 1999
00010  * Modified by:   Dag Brattli <dagb@cs.uit.no>
00011  * 
00012  *     Copyright (C) 1998-1999, Aage Kvalnes <aage@cs.uit.no>
00013  *     Copyright (c) 1998, Dag Brattli
00014  *     All Rights Reserved.
00015  *      
00016  *     This code is taken from the Vortex Operating System written by Aage
00017  *     Kvalnes and has been ported to Linux and Linux/IR by Dag Brattli
00018  *
00019  *     This program is free software; you can redistribute it and/or 
00020  *     modify it under the terms of the GNU General Public License as 
00021  *     published by the Free Software Foundation; either version 2 of 
00022  *     the License, or (at your option) any later version.
00023  *  
00024  *     Neither Dag Brattli nor University of Tromsų admit liability nor
00025  *     provide warranty for any of this software. This material is 
00026  *     provided "AS-IS" and at no charge.
00027  *     
00028  ********************************************************************/
00029 
00030 #include <linux/types.h>
00031 #include <asm/spinlock.h>
00032 
00033 #ifndef QUEUE_H
00034 #define QUEUE_H
00035 
00036 #define NAME_SIZE      32
00037 
00038 /*
00039  * Hash types
00040  */
00041 #define HB_NOLOCK      0
00042 #define HB_GLOBAL      1
00043 #define HB_LOCAL       2
00044 #define HB_SORTED      4
00045 
00046 /*
00047  * Hash defines
00048  */
00049 #define HASHBIN_SIZE   8
00050 #define HASHBIN_MASK   0x7
00051 
00052 #ifndef ALIGN 
00053 #define ALIGN __attribute__((aligned))
00054 #endif
00055 
00056 #define Q_NULL { NULL, NULL, "", 0 }
00057 
00058 typedef void (*FREE_FUNC)(void *arg);
00059 
00060 /*
00061  * Hashbin
00062  */
00063 #define GET_HASHBIN(x) ( x & HASHBIN_MASK )
00064 
00065 struct irqueue {
00066         struct irqueue *q_next;
00067         struct irqueue *q_prev;
00068 
00069         char   q_name[NAME_SIZE];
00070         __u32  q_hash;
00071 };
00072 typedef struct irqueue queue_t;
00073 
00074 typedef struct hashbin_t {
00075         __u32      magic;
00076         int        hb_type;
00077         int        hb_size;
00078         spinlock_t hb_mutex[HASHBIN_SIZE] ALIGN;
00079         queue_t   *hb_queue[HASHBIN_SIZE] ALIGN;
00080 
00081         queue_t* hb_current;
00082 } hashbin_t;
00083 
00084 hashbin_t *hashbin_new(int type);
00085 int      hashbin_delete(hashbin_t* hashbin, FREE_FUNC func);
00086 int      hashbin_clear(hashbin_t* hashbin, FREE_FUNC free_func);
00087 void     hashbin_insert(hashbin_t* hashbin, queue_t* entry, __u32 hashv, 
00088                         char* name);
00089 void*    hashbin_find(hashbin_t* hashbin, __u32 hashv, char* name);
00090 void*    hashbin_remove(hashbin_t* hashbin, __u32 hashv, char* name);
00091 void*    hashbin_remove_first(hashbin_t *hashbin);
00092 queue_t *hashbin_get_first(hashbin_t *hashbin);
00093 queue_t *hashbin_get_next(hashbin_t *hashbin);
00094 
00095 void enqueue_last(queue_t **queue, queue_t* element);
00096 void enqueue_first(queue_t **queue, queue_t* element);
00097 queue_t *dequeue_first(queue_t **queue);
00098 
00099 #define HASHBIN_GET_SIZE(hashbin) hashbin->hb_size
00100 
00101 #endif