Mail Archives: djgpp/1997/06/24/11:50:57
>
> Ok, I would like to know how you "lock" a variable.
Do you mean mutex semaphores? You have to use assembly.
> Could
> someone give me an example?
The following assembly is the shortest, though very non-ideal
semaphore routine
getsem : lock bts Reg1,Reg2; try to get the semaphore
jc getsem ; if we didn't get it try again
This does a busy wait. If you want it to be C Callable you will
have to inline it or get a param off of the stack. You will also need
a free routine which should be simple to write. To use it you just
declare a global variable to be you sempahore and then call getsem
when you want it. Your call will block until the sem becomes available
so you better have either a pre-emptive system or an ISR that changes it.
Note that typically your OS will provide functions like this if it
supports them. It will usually put your task on a non-ready queue until
the sem becomes available and let other processes run.
I probably should have checked DJ libc to see if he has support for
semaphores already (duh!) before I wrote this, but I didn't.
Maybe browse through the
posix stuff...
> Also, does Djgpp use function variables?
Do you mean function pointers? Sure. They are standard in C.
instead of doing this
int *ptr
do this
int (*fnctptr) ... ;
HTH
Andrew
- Raw text -