| 46 | } |
| 47 | |
| 48 | func (this *RWQueue) Get(event_list []interface{}, count uint32) (uint32, int) { |
| 49 | this.read_lock.Lock() |
| 50 | |
| 51 | if this.read_queue.empty() == true { |
| 52 | this.write_lock.Lock() |
| 53 | if this.exchange() == false { |
| 54 | this.write_lock.Unlock() |
| 55 | this.read_lock.Unlock() |
| 56 | return 0, 0 |
| 57 | } |
| 58 | this.write_lock.Unlock() |
| 59 | } |
| 60 | |
| 61 | read_queue := this.read_queue |
| 62 | var read_count uint32 = 0 |
| 63 | var left_count int = 0 |
| 64 | for { |
| 65 | val, ret := read_queue.pop() |
| 66 | if ret == false { |
| 67 | break |
| 68 | } |
| 69 | event_list[read_count] = val |
| 70 | read_count++ |
| 71 | if read_count == count { |
| 72 | break |
| 73 | } |
| 74 | } |
| 75 | left_count = read_queue.count() |
| 76 | this.read_lock.Unlock() |
| 77 | return read_count, left_count |
| 78 | } |
| 79 | |
| 80 | func (this *RWQueue) GetOne() interface{} { |
| 81 | this.read_lock.Lock() |