Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: semaphore.c
- Revision:
- 0:3b35413050ff
- Child:
- 3:cf23d5c2ef90
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/semaphore.c Thu Aug 04 09:56:53 2011 +0000 @@ -0,0 +1,35 @@ +#include "mbed.h" +#include "semaphore.h" + + +void semInit(semaphore* s, int initVal) +{ + *s = initVal; +} +void semPost(semaphore* s) +{ + __disable_irq(); + (*s)++; + //printf("sem released %d\n",*s); + __enable_irq(); +} +int semPend(semaphore* s, int trials) +{ + int* counter = (int*)malloc(sizeof(int)); + do + { + __disable_irq(); + //printf("sem testing %d\n",*s); + if(*s>0) + { + (*s)--; + __enable_irq(); + //printf("sem acquired\n"); + free(counter); + return SEM_OK; + } + __enable_irq(); + }while(trials > (*counter)++); + free(counter); + return SEM_ERR; +} \ No newline at end of file