Lines Matching refs:sq

47 	stream_queue_int *sq;  in CreateInternalStreamQueue()  local
49 sq = (stream_queue_int *)calloc(1, sizeof(stream_queue_int)); in CreateInternalStreamQueue()
50 if (!sq) { in CreateInternalStreamQueue()
54 sq->array = (tcp_stream **)calloc(size, sizeof(tcp_stream *)); in CreateInternalStreamQueue()
55 if (!sq->array) { in CreateInternalStreamQueue()
56 free(sq); in CreateInternalStreamQueue()
60 sq->size = size; in CreateInternalStreamQueue()
61 sq->first = sq->last = 0; in CreateInternalStreamQueue()
62 sq->count = 0; in CreateInternalStreamQueue()
64 return sq; in CreateInternalStreamQueue()
68 DestroyInternalStreamQueue(stream_queue_int *sq) in DestroyInternalStreamQueue() argument
70 if (!sq) in DestroyInternalStreamQueue()
73 if (sq->array) { in DestroyInternalStreamQueue()
74 free(sq->array); in DestroyInternalStreamQueue()
75 sq->array = NULL; in DestroyInternalStreamQueue()
78 free(sq); in DestroyInternalStreamQueue()
82 StreamInternalEnqueue(stream_queue_int *sq, struct tcp_stream *stream) in StreamInternalEnqueue() argument
84 if (sq->count >= sq->size) { in StreamInternalEnqueue()
87 "count: %d, size: %d\n", sq->count, sq->size); in StreamInternalEnqueue()
91 sq->array[sq->last++] = stream; in StreamInternalEnqueue()
92 sq->count++; in StreamInternalEnqueue()
93 if (sq->last >= sq->size) { in StreamInternalEnqueue()
94 sq->last = 0; in StreamInternalEnqueue()
96 assert (sq->count <= sq->size); in StreamInternalEnqueue()
102 StreamInternalDequeue(stream_queue_int *sq) in StreamInternalDequeue() argument
106 if (sq->count <= 0) { in StreamInternalDequeue()
110 stream = sq->array[sq->first++]; in StreamInternalDequeue()
112 if (sq->first >= sq->size) { in StreamInternalDequeue()
113 sq->first = 0; in StreamInternalDequeue()
115 sq->count--; in StreamInternalDequeue()
116 assert(sq->count >= 0); in StreamInternalDequeue()
122 NextIndex(stream_queue_t sq, index_type i) in NextIndex() argument
124 return (i != sq->_capacity ? i + 1: 0); in NextIndex()
128 PrevIndex(stream_queue_t sq, index_type i) in PrevIndex() argument
130 return (i != 0 ? i - 1: sq->_capacity); in PrevIndex()
134 StreamQueueIsEmpty(stream_queue_t sq) in StreamQueueIsEmpty() argument
136 return (sq->_head == sq->_tail); in StreamQueueIsEmpty()
148 stream_queue_t sq; in CreateStreamQueue() local
150 sq = (stream_queue_t)calloc(1, sizeof(struct stream_queue)); in CreateStreamQueue()
151 if (!sq) in CreateStreamQueue()
154 sq->_q = (tcp_stream **)calloc(capacity + 1, sizeof(tcp_stream *)); in CreateStreamQueue()
155 if (!sq->_q) { in CreateStreamQueue()
156 free(sq); in CreateStreamQueue()
160 sq->_capacity = capacity; in CreateStreamQueue()
161 sq->_head = sq->_tail = 0; in CreateStreamQueue()
163 return sq; in CreateStreamQueue()
167 DestroyStreamQueue(stream_queue_t sq) in DestroyStreamQueue() argument
169 if (!sq) in DestroyStreamQueue()
172 if (sq->_q) { in DestroyStreamQueue()
173 free((void *)sq->_q); in DestroyStreamQueue()
174 sq->_q = NULL; in DestroyStreamQueue()
177 free(sq); in DestroyStreamQueue()
181 StreamEnqueue(stream_queue_t sq, tcp_stream *stream) in StreamEnqueue() argument
183 index_type h = sq->_head; in StreamEnqueue()
184 index_type t = sq->_tail; in StreamEnqueue()
185 index_type nt = NextIndex(sq, t); in StreamEnqueue()
188 sq->_q[t] = stream; in StreamEnqueue()
189 StreamMemoryBarrier(sq->_q[t], sq->_tail); in StreamEnqueue()
190 sq->_tail = nt; in StreamEnqueue()
199 StreamDequeue(stream_queue_t sq) in StreamDequeue() argument
201 index_type h = sq->_head; in StreamDequeue()
202 index_type t = sq->_tail; in StreamDequeue()
205 tcp_stream *stream = sq->_q[h]; in StreamDequeue()
206 StreamMemoryBarrier(sq->_q[h], sq->_head); in StreamDequeue()
207 sq->_head = NextIndex(sq, h); in StreamDequeue()