#include "runtime.h"
#include "defs.h"

#line 43 "/go/src/pkg/runtime/sigqueue.goc"
static struct { 
Note; 
uint32 mask; 
bool inuse; 
} sig; 
#line 49 "/go/src/pkg/runtime/sigqueue.goc"
void 
runtime·siginit ( void ) 
{ 
runtime·noteclear ( &sig ) ; 
} 
#line 56 "/go/src/pkg/runtime/sigqueue.goc"
bool 
runtime·sigsend ( int32 s ) 
{ 
uint32 bit , mask; 
#line 61 "/go/src/pkg/runtime/sigqueue.goc"
if ( !sig.inuse ) 
return false; 
bit = 1 << s; 
for ( ;; ) { 
mask = sig.mask; 
if ( mask & bit ) 
break; 
if ( runtime·cas ( &sig.mask , mask , mask|bit ) ) { 
#line 71 "/go/src/pkg/runtime/sigqueue.goc"
if ( mask == 0 ) 
runtime·notewakeup ( &sig ) ; 
break; 
} 
} 
return true; 
} 
void
runtime·Sigrecv(uint32 m)
{
#line 80 "/go/src/pkg/runtime/sigqueue.goc"

	runtime·entersyscall();
	runtime·notesleep(&sig);
	runtime·exitsyscall();
	runtime·noteclear(&sig);
	for(;;) {
		m = sig.mask;
		if(runtime·cas(&sig.mask, m, 0))
			break;
	}
	FLUSH(&m);
}
void
runtime·Signame(int32 sig, String name)
{
#line 92 "/go/src/pkg/runtime/sigqueue.goc"

	name = runtime·signame(sig);
	FLUSH(&name);
}
void
runtime·Siginit()
{
#line 96 "/go/src/pkg/runtime/sigqueue.goc"

	runtime·initsig(SigQueue);
	sig.inuse = true;	// enable reception of signals; cannot disable
}
