我正在实现循环缓冲区,如下所示:
long windex = 0, rindex = 0, count = 0;
producer_ISR() /* whenever the data avail, then gets the interrupt */
{
/* store the data in array buffer */
array[windex] = data;
windex++;
count = count + 1; /* Increment the count */
if (windex == 32) /* overflow condition */
windex = 0;
}
consumer
{
while(1)
{
if(count > 0)
{
/* process the data */
data1 = array[rindex];
rindex++;
count = count - 1; /* decrement the count */
if (rindex == 32 ) /* overflow condition */
rindex = 0;
}
}
}
这段代码是否需要信号量来保护上述两个函数之间的共享变量“count”?
根据我的分析,信号量不是必需的,请分享您的想法。