Effo Design - Lock-free Queue and Ring Buffer
Table of Content
Lock-free Queue and Ring Buffer..................................................................................1
1. Document Revision History ........................................................................................ 5
2. Documents and Code URL ......................................................................................... 5
3. What will we Design .................................................................................................. 5
4. The Effo Project .......................................................................................................... 6
4.1 Introductions ...................................................................................................... 6
4.2 Divide and Rule ................................................................................................. 7
5. Base LIFO ................................................................................................................... 7
5.1 Single-linked List ............................................................................................... 8
5.2 Creator ............................................................................................................... 8
5.3 Node .................................................................................................................. 9
5.4 Head and Push-Front ....................................................................................... 11
5.5 Front and Pop-Front ......................................................................................... 13
5.6 Coding Example ............................................................................................... 13
5.7 To-do Next ....................................................................................................... 13
6. Atomic Operations ................................................................................................... 13
6.1 i++ is not Atomic ............................................................................................ 13
6.2 Get Atomic Primitive ........................................................................................ 14
6.3 Compare with pthread Lock ............................................................................. 15
6.4 Test Results ...................................................................................................... 16
6.5 sync_plc_none and efao Polices ...................................................................... 17
7. sync_queue .............................................................................................................. 20
7.1 Tail, List Head and Queue Head ....................................................................... 20
7.2 front() and push() ............................................................................................ 21
7.3 pop() ................................................................................................................ 22
7.4 Coding Example ............................................................................................... 23
8. Base Ringed ............................................................................................................. 24
8.1 The Template ................................................................................................... 24
8.2 The Stuff .......................................................................................................... 25
8.3 The Snapshot ................................................................................................... 26
8.4 The Operations ................................................................................................ 27
8.5 How a Ringed Buffer Works ............................................................................. 27
8.6 SizeUsed and SizeFree ..................................................................................... 28
8.7 CanPush() and CanPop() .................................................................................. 29
8.8 Quick Accessing Host from a Guest ................................................................. 29
9. Ring Buffer ............................................................................................................... 30
9.1 push() .............................................................................................................. 30
9.2 pop() ................................................................................................................ 32
9.3 The Wrapper ring_buffer .................................................................................. 33
9.4 ring_buffer Code Example ............................................................................... 34
10. Ring Queue ............................................................................................................ 34
10.1 push() ............................................................................................................ 34
3
Copyright © 2008,2009 The Effo Core project. All rights reserved.