rt-thread 僵尸线程怎么 销毁,一直占用资源
thread_play = rt_thread_create(“wav_play”,thread_wavplay, argv[1],2048, 2, 25);
/ 启 动 线 程 /
if (thread_play != RT_NULL) rt_thread_startup(thread_play);
void thread_wavplay(void parameter)
{
int fd = -1;
uint8_t buffer = NULL;
struct wav_info *info = NULL;
struct rt_audio_caps caps = {0};
//fd = open("/sd/sine.wav ", O_RDONLY);
fd = open( (const char )( parameter ), O_RDONLY);
if (fd < 0)
{
rt_kprintf("open file failed!\n");
goto __exit;
}
buffer = rt_malloc(BUFSZ);
if (buffer == RT_NULL)
goto __exit;
info = (struct wav_info ) rt_malloc(sizeof * info);
if (info == RT_NULL)
goto __exit;
if (read(fd, &(info->header), sizeof(struct RIFF_HEADER_DEF)) <= 0)
goto __exit;
if (read(fd, &(info->fmt_block), sizeof(struct FMT_BLOCK_DEF)) <= 0)
goto __exit;
if (read(fd, &(info->data_block), sizeof(struct DATA_BLOCK_DEF)) <= 0)
goto __exit;
rt_kprintf("wav information:\n");
rt_kprintf("samplerate %d\n", info->fmt_block.wav_format.SamplesPerSec);
rt_kprintf("channel %d\n", info->fmt_block.wav_format.Channels);
/ 根据设备名称查找 Audio 设备,获取设备句柄 /
snd_dev = rt_device_find(SOUND_DEVICE_NAME);
/ 以只写方式打开 Audio 播放设备 /
rt_device_open(snd_dev, RT_DEVICE_OFLAG_WRONLY);
/ 设置采样率、通道、采样位数等音频参数信息 /
caps.main_type = AUDIO_TYPE_OUTPUT; / 输出类型(播放设备 )/
caps.sub_type = AUDIO_DSP_PARAM; /* 设置所有音频参数信息 /
caps.udata.config.samplerate = info->fmt_block.wav_format.SamplesPerSec; / 采样率 /
caps.udata.config.channels = info->fmt_block.wav_format.Channels; / 采样通道 /
caps.udata.config.samplebits = 16; / 采样位数 */
rt_device_control(snd_dev, AUDIO_CTL_CONFIGURE, &caps);
while (1)
{
int length;
int i;
uint16_t *p_buff; //wav 音频数据有符号
//int16_t p_buff;
/ 从文件系统读取 wav 文件的音频数据 */
length = read(fd, buffer, BUFSZ);
p_buff = (uint16_t )buffer;
if (length <= 0)
break;
/ 向 Audio 设备写入音频数据 /
rt_device_write(snd_dev, 0, buffer, length);
}
/ 关闭 Audio 设备 */
rt_device_close(snd_dev);
__exit:
if (fd >= 0)
close(fd);
if (buffer)
rt_free(buffer);
if (info)
rt_free(info);
return ;
}
sys workq 23 ready
tidle0 31 ready
这2个线程 一直都是 就绪状态, tidle0 应该是一直没执行, sys workq 没用到这个线程
更多回帖