Advertisement
Guest User

RCU dependency chain 3

a guest
Aug 2nd, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. 1 /* Does this work? */
  2. 2 struct foo my_foo = { 5, 10 };
  3. 3
  4. 4 struct foo *insert_struct(struct foo *p)
  5. 5 {
  6. 6 struct foo *q;
  7. 7
  8. 8 if (data < 0)
  9. 9 return NULL;
  10. 10 spin_lock(gp_lock);
  11. 11 q = atomic_xchg(&gp, p);
  12. 12 spin_unlock(gp_lock);
  13. 13 synchronize_rcu();
  14. 14 return q;
  15. 15 }
  16. 16
  17. 17 ...
  18. 18 WARN_ON_ONCE(insert_struct(&my_foo));
  19. 19 ...
  20. 20
  21. 21 int lookup3(int key)
  22. 22 {
  23. 23 struct foo *p;
  24. 24 int data;
  25. 25
  26. 26 rcu_read_lock();
  27. 27 p = rcu_dereference(gp);
  28. 28 if (p != NULL && p->key == key)
  29. 29 data = p->data;
  30. 30 else if (p == &myfoo)
  31. 31 data = p->data * p->data;
  32. 32 else
  33. 33 data = -1;
  34. 34 rcu_read_unlock();
  35. 35 return data;
  36. 36 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement