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.
semaphore.c
- Committer:
- umutaradag
- Date:
- 2011-08-06
- Revision:
- 3:cf23d5c2ef90
- Parent:
- 0:3b35413050ff
File content as of revision 3:cf23d5c2ef90:
#include "mbed.h" #include "semaphore.h" void semInit(semaphore* s, int initVal) { s->count = initVal; } void semPost(semaphore* s) { __disable_irq(); s->count++; //printf("sem released %d\n",*s); __enable_irq(); } int semPend(semaphore* s, int maxNumOfTrials) { s->trials = 0; do { __disable_irq(); //printf("sem testing %d\n",*s); if(s->count > 0) { s->count--; __enable_irq(); //printf("sem acquired\n"); return SEM_OK; } __enable_irq(); }while(maxNumOfTrials > s->trials++); return SEM_ERR; } void semSet(semaphore* s, int val) { s->count = val; }