FreeRTOS中的优先天花板协议(PCP)

时间:2019-03-03 11:30:21

标签: mutex job-scheduling freertos

我想通过围绕FreeRTOS API制作包装函数来在FreeRTOS中实现PCP。这是使用PCP获取互斥量的包装器代码。

UBaseType_t PCP_mutex_take(mutex_handle, task_handle) {

    UBaseType_t ret_val = pdFALSE;

    // Returns the semaphore S* ('p_highest_ceiling_semaphore')
    // with the highest priority ceiling of all semaphores
    // currently locked by jobs other than job J ('task_handle')
    p_highest_ceiling_semaphore = get_highest_ceiling_semaphore(task_handle);

    // Job J will be blocked and the lock on S (mutex_handle) will be denied, if the priority
    // of job J is not higher than the priority ceiling of semaphore S*
    if (uxTaskPriorityGet(task_handle) > p_highest_ceiling_semaphore.ceiling) {
        // We can try to obtain the lock according to PCP 
        xSemaphoreTake(mutex, ((TickType_t)portMAX_DELAY);
        {
            add_to_currently_locked_semaphore_list(mutex);
            ret_val = pdTRUE;
        }
    } 
    else {
        block 'task_handle' on 'p_highest_ceiling_semaphore'   
        ret_val = pdFALSE;
    }  
}

作为原始论文 [优先级继承协议,L.Sha,R. Rajkumar等,J.P。Lehoczky] 中的PCP算法”说: “如果作业J的优先级不高于当前被其他作业锁定的所有信号量中具有最高优先级上限的信号量的优先级上限,则具有最高优先级的任务J将被阻止并且对S的锁定将被拒绝。比工作J要好。”

所以在else分支中,我想精确地执行句子的第二部分。但是,当我在else分支xSemaphoreTake(pHighestCeilingLockedSemaphore->semphHandle, (TickType_t)portMAX_DELAY);内插入时,由于没有安排其他任务,因此似乎出现了死锁情况?

如何在不显式调用xSemaphoreTake的情况下阻止某个信号量上的任务?

0 个答案:

没有答案
相关问题