lkml.org 
[lkml]   [1996]   [May]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 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.


\
 
 \ /
  Last update: 2005-03-22 13:37    [W:0.513 / U:0.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site