Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4973 right-hear 1
#ifndef __QUEUE_H
2
#define __QUEUE_H
3
 
4
#include
5
#include
6
 
7
typedef struct
8
{
9
 int in_ptr,out_ptr,size;
10
 unsigned char * databuf;
11
 DECLARE_SEMAPHORE_S(q_lock);
12
} __oe_queue_t;
13
 
14
#define DECL_EMPTY_Q(n,sz,buf)	__oe_queue_t n = {0,0,sz,buf,SEM_INIT}
15
 
16
#define __OE_QUEUE_INQ(x,c) \
17
    ({ \
18
	register int __ret,temp; \
19
	sem_lock(&(x)->q_lock); \
20
	temp=(x)->in_ptr+1; \
21
	if(temp>=(x)->size) temp=0; \
22
	if(temp==(x)->out_ptr) { __ret=-1; goto __OEQI_D; } \
23
	(x)->databuf[(x)->in_ptr]=(c)&0xFF; \
24
	(x)->in_ptr=temp; \
25
	__ret=0; \
26
__OEQI_D: \
27
	sem_unlock(&(x)->q_lock); \
28
	__ret; })
29
 
30
#define __OE_QUEUE_DEQ(x,c) \
31
    ({ \
32
	register int __ret; \
33
	register unsigned char __tmp; \
34
	sem_lock(&(x)->q_lock); \
35
	if((x)->out_ptr==(x)->in_ptr) { __ret=-1; goto __OEQD_D; } \
36
	__tmp=(x)->databuf[(x)->out_ptr++]; \
37
	if((x)->out_ptr>=(x)->size) (x)->out_ptr=0; \
38
	__ret=0; \
39
	(c)=__tmp; \
40
__OEQD_D: \
41
	sem_unlock(&(x)->q_lock); \
42
	__ret; })
43
 
44
#endif