Messages in this thread |  | | Date | Wed, 8 May 1996 01:57:55 -0700 | From | Tom May <> | Subject | Re: clone() and pthreads? |
| |
Linus Torvalds <torvalds@cs.helsinki.fi> writes:
Umm.. My suggestion for a semaphore would be something along these lines:
struct semaphore { long count; unsigned long waiting; /* bitmap of interested threads */ };
__asm__("lock ; decl %0\n\t" /* subtract one from sem->count */ "jns 1f\n\t" /* success? */ "pushl %1\n\t" "jsr __wait_semaphore\n\t" "popl %1\n" "1:" :"=m" (sem->count) :"r" (sem) :"ax","dx","cx","memory"); /* clobbered by function call */
0. You mean "call", not "jsr" . . . 1. You don't want to pop back into %1 because it's an __asm__ input only, and the __wait_semaphore function *may* modify the value on the stack. It would be most efficient to pop into one of the call-clobbered registers. 2. sem->count should probably be both an input and an output, but it may not matter in actual practice.
So we get:
__asm__("lock ; decl %0\n\t" /* subtract one from sem->count */ "jns 1f\n\t" /* success? */ "pushl %1\n\t" "call __wait_semaphore\n\t" "popl %%eax\n" "1:" :"=m" (sem->count) :"r" (sem), "0" (sem->count) :"ax","dx","cx","memory"); /* clobbered by function call */
Tom.
|  |