cvra / platform-abstraction

Platform abstraction layer for microcontrollers
3 stars 6 forks source link

Mock support for semaphores #1

Closed antoinealb closed 10 years ago

antoinealb commented 10 years ago

This pull request implements semaphores for the "mock platform" used in testing. Once the API has been reviewed, I will implement the real (uc/OS-III) semaphores.

pierluca commented 10 years ago

Interface LGTM. Mock implementation is incomplete:

On a separate note, is something as long as "platform" really necessary? what about "os" ? I can't imagine typing platform_semaphore_release more than a few times without being annoyed by it :-)

antoinealb commented 10 years ago

for point 3 (count <= max_count) uc/OS-3 doesn't assert this, so tests should not IMHO.

idk what is the best option to emulate waiting on a ressource since all tests will (probably) run single threaded.

Agree on the platform_* function name being too long, will change.

froj commented 10 years ago

The function platform_semaphore_take should either be

void platform_semaphore_take(semaphore_t *sem)
{
    while(sem->count < 1) {
        suspend();
    }
    sem->count--;
    sem->acquired_count++;
}

or

int platform_semaphore_accept(semaphore_t *sem)
{
    if(sem->count > 0) {
        sem->count--;
        sem->acquired_count++;
    }
    return sem->count;
}

but I agree that it's hard to emulate suspension in a single thread.

antoinealb commented 10 years ago

Do we have a real use case where we need to emulate suspension ?

antoinealb commented 10 years ago

Waaaaaaat, sorry I had a problem with Git when enabling Travis CI. Did not mean to merge.

I still have to learn my way around all of this, travis CI, pull request and so on.