/*=================================== * * 消息发送 *===================================*/ acoral_u32 acoral_msg_send(acoral_msgctr_t* msgctr, acoral_msg_t* msg) { acoral_sr cpu_sr; /* if (acoral_intr_nesting > 0) return MST_ERR_INTR; */ HAL_ENTER_CRITICAL(); acoral_spin_lock(&msgctr->spin_lock); if (NULL == msgctr) { acoral_spin_unlock(&msgctr->spin_lock); HAL_EXIT_CRITICAL(); return MST_ERR_NULL; } if (NULL == msg) { acoral_spin_unlock(&msgctr->spin_lock); HAL_EXIT_CRITICAL(); return MSG_ERR_NULL; } /*----------------*/ /* 消息数限制*/ /*----------------*/ if (ACORAL_MESSAGE_MAX_COUNT <= msgctr->count) { acoral_spin_unlock(&msgctr->spin_lock); HAL_EXIT_CRITICAL(); return MSG_ERR_COUNT; } /*----------------*/ /* 增加消息*/ /*----------------*/ msgctr->count++; msg->ttl += acoral_get_ticks(); acoral_list_add2_tail(&msg->msglist, &msgctr->msglist); /*----------------*/ /* 唤醒等待*/ /*----------------*/ if (msgctr->wait_thread_num > 0) { /* 此处将最高优先级唤醒*/ wake_up_thread(&msgctr->waiting); msgctr->wait_thread_num--; } acoral_spin_unlock(&msgctr->spin_lock); HAL_EXIT_CRITICAL(); acoral_sched(); return MSGCTR_SUCCED; }
static BOOL WINAPI ctrl_handler(DWORD dwCtrlType) { switch (dwCtrlType) { case CTRL_C_EVENT: { // The CtrlHandler runs in its own thread without stopping the main // thread. Since in practice nobody uses the multi-VM stuff yet, we just // grab the first VM we can get. This will not be a good idea when we // actually support native threads. FACTOR_ASSERT(thread_vms.size() == 1); factor_vm* vm = thread_vms.begin()->second; vm->enqueue_fep(); // Before leaving the ctrl_handler, try and wake up the main thread. wake_up_thread(factor::boot_thread); return TRUE; } default: return FALSE; } }