0
我實現循環緩衝器如下:此循環緩衝區實現是否需要信號量?
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 = 1/0互斥量比信號量更方便,對不對? –