Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 214451
b: refs/heads/master
c: fbf4d7e
h: refs/heads/master
i:
  214449: 7bfd4db
  214447: 6a26a04
v: v3
  • Loading branch information
Andy Grover committed Sep 9, 2010
1 parent 84c164d commit 4c846ab
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 43 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: c9455d9996ba84af1f534c7e3944ea6f35d2fc54
refs/heads/master: fbf4d7e3d03587a983ee4e536251ea6c1c848ec2
54 changes: 12 additions & 42 deletions trunk/net/rds/xlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ struct xlist_head {
struct xlist_head *next;
};

/*
* XLIST_PTR_TAIL can be used to prevent double insertion. See
* xlist_protect()
*/
#define XLIST_PTR_TAIL ((struct xlist_head *)0x1)
static inline void INIT_XLIST_HEAD(struct xlist_head *list)
{
list->next = NULL;
}

static inline int xlist_empty(struct xlist_head *head)
{
return head->next == NULL;
}

static inline void xlist_add(struct xlist_head *new, struct xlist_head *tail, struct xlist_head *head)
static inline void xlist_add(struct xlist_head *new, struct xlist_head *tail,
struct xlist_head *head)
{
struct xlist_head *cur;
struct xlist_head *check;
Expand All @@ -30,26 +35,6 @@ static inline void xlist_add(struct xlist_head *new, struct xlist_head *tail, st
}
}

/*
* To avoid duplicate insertion by two CPUs of the same xlist item
* you can call xlist_protect. It will stuff XLIST_PTR_TAIL
* into the entry->next pointer with xchg, and only return 1
* if there was a NULL there before.
*
* if xlist_protect returns zero, someone else is busy working
* on this entry. Getting a NULL into the entry in a race
* free manner is the caller's job.
*/
static inline int xlist_protect(struct xlist_head *entry)
{
struct xlist_head *val;

val = xchg(&entry->next, XLIST_PTR_TAIL);
if (val == NULL)
return 1;
return 0;
}

static inline struct xlist_head *xlist_del_head(struct xlist_head *head)
{
struct xlist_head *cur;
Expand All @@ -61,11 +46,6 @@ static inline struct xlist_head *xlist_del_head(struct xlist_head *head)
if (!cur)
goto out;

if (cur == XLIST_PTR_TAIL) {
cur = NULL;
goto out;
}

next = cur->next;
check = cmpxchg(&head->next, cur, next);
if (check == cur)
Expand All @@ -80,7 +60,7 @@ static inline struct xlist_head *xlist_del_head_fast(struct xlist_head *head)
struct xlist_head *cur;

cur = head->next;
if (!cur || cur == XLIST_PTR_TAIL)
if (!cur)
return NULL;

head->next = cur->next;
Expand All @@ -97,14 +77,4 @@ static inline void xlist_splice(struct xlist_head *list,
head->next = cur;
}

static inline void INIT_XLIST_HEAD(struct xlist_head *list)
{
list->next = NULL;
}

static inline int xlist_empty(struct xlist_head *head)
{
return head->next == NULL || head->next == XLIST_PTR_TAIL;
}

#endif

0 comments on commit 4c846ab

Please sign in to comment.