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