/* * SysApi recv * 参数:无 * 功能:接受消息,如果没有消息则睡眠自己 * 返回值:消息头 */ MsgHead recv() { KernelLock(); int priority = 10; // -12 int id; Bool empty = True; // -20 /* 循环等待接收消息 */ for(int i=0;i<THREAD_NR_MSGQUEUE/32;i++) // -24 { empty = empty && (thread_run->thread_info.msg_queue_bmp[i] == 0); } if (empty) { thread_run->thread_info.state = THREAD_STATE_RECVING; KernelUnlock(); wait(); } /* 选择优先级最高的消息 */ for(int i=0;i<THREAD_NR_MSGQUEUE;i++) { if(bmp_test((void*)&thread_run->thread_info.msg_queue_bmp,i)) { /* 获取消息指针 */ MsgHead *msg = &thread_run->thread_info.msg_queue[i]; /* 如果消息的优先级已最高 */ if(msg->priority == 0) { bmp_clear((void*)&thread_run->thread_info.msg_queue_bmp,i); return *msg; } /* 选择较高优先级的消息 */ if(msg->priority < priority) { id = i; priority = msg->priority; } } } bmp_clear((void*)&thread_run->thread_info.msg_queue_bmp,id); KernelUnlock(); return thread_run->thread_info.msg_queue[id]; }
int stbi_bmp_test_memory (stbi_uc const *buffer, int len) { stbi s; start_mem(&s, buffer, len); return bmp_test(&s); }