irqueue.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*********************************************************************
  2. *
  3. * Filename: irqueue.h
  4. * Version: 0.3
  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 Oct 7 13:25:16 1999
  10. * Modified by: Dag Brattli <dagb@cs.uit.no>
  11. *
  12. * Copyright (C) 1998-1999, Aage Kvalnes <aage@cs.uit.no>
  13. * Copyright (c) 1998, Dag Brattli
  14. * All Rights Reserved.
  15. *
  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
  18. *
  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.
  23. *
  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.
  27. *
  28. ********************************************************************/
  29. #include <linux/types.h>
  30. #include <linux/spinlock.h>
  31. #ifndef IRDA_QUEUE_H
  32. #define IRDA_QUEUE_H
  33. #define NAME_SIZE 32
  34. /*
  35. * Hash types (some flags can be xored)
  36. * See comments in irqueue.c for which one to use...
  37. */
  38. #define HB_NOLOCK 0 /* No concurent access prevention */
  39. #define HB_LOCK 1 /* Prevent concurent write with global lock */
  40. /*
  41. * Hash defines
  42. */
  43. #define HASHBIN_SIZE 8
  44. #define HASHBIN_MASK 0x7
  45. #ifndef IRDA_ALIGN
  46. #define IRDA_ALIGN __attribute__((aligned))
  47. #endif
  48. #define Q_NULL { NULL, NULL, "", 0 }
  49. typedef void (*FREE_FUNC)(void *arg);
  50. struct irda_queue {
  51. struct irda_queue *q_next;
  52. struct irda_queue *q_prev;
  53. char q_name[NAME_SIZE];
  54. long q_hash; /* Must be able to cast a (void *) */
  55. };
  56. typedef struct irda_queue irda_queue_t;
  57. typedef struct hashbin_t {
  58. __u32 magic;
  59. int hb_type;
  60. int hb_size;
  61. spinlock_t hb_spinlock; /* HB_LOCK - Can be used by the user */
  62. irda_queue_t* hb_queue[HASHBIN_SIZE] IRDA_ALIGN;
  63. irda_queue_t* hb_current;
  64. } hashbin_t;
  65. hashbin_t *hashbin_new(int type);
  66. int hashbin_delete(hashbin_t* hashbin, FREE_FUNC func);
  67. int hashbin_clear(hashbin_t* hashbin, FREE_FUNC free_func);
  68. void hashbin_insert(hashbin_t* hashbin, irda_queue_t* entry, long hashv,
  69. const char* name);
  70. void* hashbin_remove(hashbin_t* hashbin, long hashv, const char* name);
  71. void* hashbin_remove_first(hashbin_t *hashbin);
  72. void* hashbin_remove_this( hashbin_t* hashbin, irda_queue_t* entry);
  73. void* hashbin_find(hashbin_t* hashbin, long hashv, const char* name);
  74. void* hashbin_lock_find(hashbin_t* hashbin, long hashv, const char* name);
  75. void* hashbin_find_next(hashbin_t* hashbin, long hashv, const char* name,
  76. void ** pnext);
  77. irda_queue_t *hashbin_get_first(hashbin_t *hashbin);
  78. irda_queue_t *hashbin_get_next(hashbin_t *hashbin);
  79. #define HASHBIN_GET_SIZE(hashbin) hashbin->hb_size
  80. #endif