Lines Matching refs:hashbin

53  * Notes on the concurrent access to hashbin and other SMP issues
59 * management of concurrent access to the hashbin and how to guarantee the
63 * 1) Protect user data (content pointed by the hashbin)
64 * 2) Protect hashbin structure itself (linked list in each bin)
76 * B) No protection for the hashbin struct global data
89 * hashbin :
93 * As the data is still in the hashbin, it may be changed or free'd
95 * be done within the hashbin, but must include use of the data within
108 * hashbin locking :
110 * 2) hashbin->hb_spinlock
111 * 3) New hashbin usage policy
117 * of the hashbin. As it is a single spinlock, it can protect the global
118 * data of the hashbin and not only the bins themselves.
119 * HB_LOCK can only protect some of the hashbin calls, so it only lock
121 * HB_LOCK in theory is slower than HB_GLOBAL, but as the hashbin
125 * hashbin->hb_spinlock :
132 * spin_lock_irqsave(&hashbin->hb_spinlock, flags);
134 * spin_unlock_irqrestore(&hashbin->hb_spinlock, flags);
147 * The following calls only protect the hashbin itself :
160 * If the hashbin is used only in a single thread of execution
165 * In all other cases, you need to use HB_LOCK and lock the hashbin
172 * hashbin_get_first() and hashbin_get_next() use the hashbin to
174 * As long as the hashbin remains locked, this is safe. If you unlock
175 * the hashbin, the current position may change if anybody else modify
176 * or enumerate the hashbin.
180 * be slower, is more complex to use and doesn't protect the hashbin
188 * Don't believe that because hashbin are now (somewhat) SMP safe
350 * Create hashbin!
355 hashbin_t* hashbin;
358 * Allocate new hashbin
360 hashbin = kzalloc(sizeof(*hashbin), GFP_ATOMIC);
361 if (!hashbin)
367 hashbin->hb_type = type;
368 hashbin->magic = HB_MAGIC;
369 //hashbin->hb_current = NULL;
372 if ( hashbin->hb_type & HB_LOCK ) {
373 spin_lock_init(&hashbin->hb_spinlock);
376 return hashbin;
382 * Function hashbin_delete (hashbin, free_func)
384 * Destroy hashbin, the free_func can be a user supplied special routine
391 int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func)
397 IRDA_ASSERT(hashbin != NULL, return -1;);
398 IRDA_ASSERT(hashbin->magic == HB_MAGIC, return -1;);
401 if ( hashbin->hb_type & HB_LOCK ) {
402 spin_lock_irqsave_nested(&hashbin->hb_spinlock, flags,
407 * Free the entries in the hashbin, TODO: use hashbin_clear when
411 queue = dequeue_first((irda_queue_t**) &hashbin->hb_queue[i]);
416 (irda_queue_t**) &hashbin->hb_queue[i]);
421 hashbin->hb_current = NULL;
422 hashbin->magic = ~HB_MAGIC;
425 if ( hashbin->hb_type & HB_LOCK) {
426 spin_unlock_irqrestore(&hashbin->hb_spinlock, flags);
433 * Free the hashbin structure
435 kfree(hashbin);
444 * Function hashbin_insert (hashbin, entry, name)
446 * Insert an entry into the hashbin
449 void hashbin_insert(hashbin_t* hashbin, irda_queue_t* entry, long hashv,
457 IRDA_ASSERT( hashbin != NULL, return;);
458 IRDA_ASSERT( hashbin->magic == HB_MAGIC, return;);
461 * Locate hashbin
468 if ( hashbin->hb_type & HB_LOCK ) {
469 spin_lock_irqsave(&hashbin->hb_spinlock, flags);
482 enqueue_first( (irda_queue_t**) &hashbin->hb_queue[ bin ],
484 hashbin->hb_size++;
487 if ( hashbin->hb_type & HB_LOCK ) {
488 spin_unlock_irqrestore(&hashbin->hb_spinlock, flags);
494 * Function hashbin_remove_first (hashbin)
496 * Remove first entry of the hashbin
502 void *hashbin_remove_first( hashbin_t *hashbin)
508 if ( hashbin->hb_type & HB_LOCK ) {
509 spin_lock_irqsave(&hashbin->hb_spinlock, flags);
512 entry = hashbin_get_first( hashbin);
517 * Locate hashbin
525 dequeue_general( (irda_queue_t**) &hashbin->hb_queue[ bin ],
527 hashbin->hb_size--;
535 if ( entry == hashbin->hb_current)
536 hashbin->hb_current = NULL;
540 if ( hashbin->hb_type & HB_LOCK ) {
541 spin_unlock_irqrestore(&hashbin->hb_spinlock, flags);
549 * Function hashbin_remove (hashbin, hashv, name)
562 void* hashbin_remove( hashbin_t* hashbin, long hashv, const char* name)
570 IRDA_ASSERT( hashbin != NULL, return NULL;);
571 IRDA_ASSERT( hashbin->magic == HB_MAGIC, return NULL;);
574 * Locate hashbin
581 if ( hashbin->hb_type & HB_LOCK ) {
582 spin_lock_irqsave(&hashbin->hb_spinlock, flags);
588 entry = hashbin->hb_queue[ bin ];
610 } while ( entry != hashbin->hb_queue[ bin ] );
617 dequeue_general( (irda_queue_t**) &hashbin->hb_queue[ bin ],
619 hashbin->hb_size--;
625 if ( entry == hashbin->hb_current)
626 hashbin->hb_current = NULL;
630 if ( hashbin->hb_type & HB_LOCK ) {
631 spin_unlock_irqrestore(&hashbin->hb_spinlock, flags);
645 * Function hashbin_remove_this (hashbin, entry)
649 * In some cases, the user of hashbin can't guarantee the unicity
655 void* hashbin_remove_this( hashbin_t* hashbin, irda_queue_t* entry)
663 IRDA_ASSERT( hashbin != NULL, return NULL;);
664 IRDA_ASSERT( hashbin->magic == HB_MAGIC, return NULL;);
668 if ( hashbin->hb_type & HB_LOCK ) {
669 spin_lock_irqsave(&hashbin->hb_spinlock, flags);
679 * Locate hashbin
687 dequeue_general( (irda_queue_t**) &hashbin->hb_queue[ bin ],
689 hashbin->hb_size--;
697 if ( entry == hashbin->hb_current)
698 hashbin->hb_current = NULL;
701 if ( hashbin->hb_type & HB_LOCK ) {
702 spin_unlock_irqrestore(&hashbin->hb_spinlock, flags);
712 * Function hashbin_common_find (hashbin, hashv, name)
717 void* hashbin_find( hashbin_t* hashbin, long hashv, const char* name )
724 IRDA_ASSERT( hashbin != NULL, return NULL;);
725 IRDA_ASSERT( hashbin->magic == HB_MAGIC, return NULL;);
728 * Locate hashbin
737 entry = hashbin->hb_queue[ bin];
756 } while ( entry != hashbin->hb_queue[ bin ] );
764 * Function hashbin_lock_find (hashbin, hashv, name)
769 * I call it safe, but it's only safe with respect to the hashbin, not its
772 void* hashbin_lock_find( hashbin_t* hashbin, long hashv, const char* name )
778 spin_lock_irqsave(&hashbin->hb_spinlock, flags);
783 entry = hashbin_find(hashbin, hashv, name);
786 spin_unlock_irqrestore(&hashbin->hb_spinlock, flags);
793 * Function hashbin_find (hashbin, hashv, name, pnext)
802 void* hashbin_find_next( hashbin_t* hashbin, long hashv, const char* name,
809 spin_lock_irqsave(&hashbin->hb_spinlock, flags);
814 * hashbin or has been removed.
816 entry = hashbin_find(hashbin, hashv, name);
822 hashbin->hb_current = entry;
823 *pnext = hashbin_get_next( hashbin );
828 spin_unlock_irqrestore(&hashbin->hb_spinlock, flags);
834 * Function hashbin_get_first (hashbin)
836 * Get a pointer to first element in hashbin, this function must be
840 irda_queue_t *hashbin_get_first( hashbin_t* hashbin)
845 IRDA_ASSERT( hashbin != NULL, return NULL;);
846 IRDA_ASSERT( hashbin->magic == HB_MAGIC, return NULL;);
848 if ( hashbin == NULL)
852 entry = hashbin->hb_queue[ i];
854 hashbin->hb_current = entry;
859 * Did not find any item in hashbin
866 * Function hashbin_get_next (hashbin)
868 * Get next item in hashbin. A series of hashbin_get_next() calls must
872 * The context of the search is stored within the hashbin, so you must
875 irda_queue_t *hashbin_get_next( hashbin_t *hashbin)
881 IRDA_ASSERT( hashbin != NULL, return NULL;);
882 IRDA_ASSERT( hashbin->magic == HB_MAGIC, return NULL;);
884 if ( hashbin->hb_current == NULL) {
885 IRDA_ASSERT( hashbin->hb_current != NULL, return NULL;);
888 entry = hashbin->hb_current->q_next;
895 if ( entry != hashbin->hb_queue[ bin ]) {
896 hashbin->hb_current = entry;
902 * Check that this is not the last queue in hashbin
908 * Move to next queue in hashbin
912 entry = hashbin->hb_queue[ i];
914 hashbin->hb_current = entry;