示例#1
0
文件: qio.c 项目: 8l/inferno
/*
 *  Mark a queue as closed.  No further IO is permitted.
 *  All blocks are released.
 */
void
qclose(Queue *q)
{
	Block *bfirst;

	if(q == nil)
		return;

	/* mark it */
	lock(&q->l);
	q->state |= Qclosed;
	q->state &= ~(Qflow|Qstarve);
	strcpy(q->err, Ehungup);
	bfirst = q->bfirst;
	q->bfirst = 0;
	q->len = 0;
	q->dlen = 0;
	q->noblock = 0;
	unlock(&q->l);

	/* free queued blocks */
	freeblist(bfirst);

	/* wake up readers/writers */
	Wakeup(&q->rr);
	Wakeup(&q->wr);
}
示例#2
0
文件: devcmd.c 项目: 8l/inferno
static void
cmdproc(void *a)
{
	Conv *c;
	int n;
	char status[ERRMAX];
	void *t;

	c = a;
	qlock(&c->l);
	if(Debug)
		print("f[0]=%q f[1]=%q\n", c->cmd->f[0], c->cmd->f[1]);
	if(waserror()){
		if(Debug)
			print("failed: %q\n", up->env->errstr);
		kstrdup(&c->error, up->env->errstr);
		c->state = "Done";
		qunlock(&c->l);
		Wakeup(&c->startr);
		pexit("cmdproc", 0);
	}
	t = oscmd(c->cmd->f+1, c->nice, c->dir, c->fd);
	if(t == nil)
		oserror();
	c->child = t;	/* to allow oscmdkill */
	poperror();
	qunlock(&c->l);
	Wakeup(&c->startr);
	if(Debug)
		print("started\n");
	while(waserror())
		oscmdkill(t);
	osenter();
	n = oscmdwait(t, status, sizeof(status));
	osleave();
	if(n < 0){
		oserrstr(up->genbuf, sizeof(up->genbuf));
		n = snprint(status, sizeof(status), "0 0 0 0 %q", up->genbuf);
	}
	qlock(&c->l);
	c->child = nil;
	oscmdfree(t);
	if(Debug){
		status[n]=0;
		print("done %d %d %d: %q\n", c->fd[0], c->fd[1], c->fd[2], status);
	}
	if(c->inuse > 0){
		c->state = "Done";
		if(c->waitq != nil)
			qproduce(c->waitq, status, n);
	}else
		closeconv(c);
	qunlock(&c->l);
	pexit("", 0);
}
示例#3
0
文件: qio.c 项目: 8l/inferno
/*
 *  Mark a queue as closed.  Wakeup any readers.  Don't remove queued
 *  blocks.
 */
void
qhangup(Queue *q, char *msg)
{
	/* mark it */
	lock(&q->l);
	q->state |= Qclosed;
	if(msg == 0 || *msg == 0)
		strcpy(q->err, Ehungup);
	else
		kstrcpy(q->err, msg, sizeof q->err);
	unlock(&q->l);

	/* wake up readers/writers */
	Wakeup(&q->rr);
	Wakeup(&q->wr);
}
示例#4
0
文件: qio.c 项目: 8l/inferno
/*
 *  get next block from a queue, return null if nothing there
 */
Block*
qget(Queue *q)
{
	int dowakeup;
	Block *b;

	/* sync with qwrite */
	lock(&q->l);

	b = q->bfirst;
	if(b == 0){
		q->state |= Qstarve;
		unlock(&q->l);
		return 0;
	}
	q->bfirst = b->next;
	b->next = 0;
	q->len -= BALLOC(b);
	q->dlen -= BLEN(b);
	QDEBUG checkb(b, "qget");

	/* if writer flow controlled, restart */
	if((q->state & Qflow) && q->len < q->limit/2){
		q->state &= ~Qflow;
		dowakeup = 1;
	} else
		dowakeup = 0;

	unlock(&q->l);

	if(dowakeup)
		Wakeup(&q->wr);

	return b;
}
// ---------------------------------------------------------------------------
// CTurnAsyncCallback::MakeCallbackL
// ---------------------------------------------------------------------------
//
void CTurnAsyncCallback::MakeCallbackL(
    TTurnPluginCallbackInfo::TFunction aFunction,
    TUint aStreamId,
    TInt aErrorCode,
    TAny* aEventData )
    {
    TTurnPluginCallbackInfo* callback =
        new ( ELeave ) TTurnPluginCallbackInfo( iTurnPlugin,
                                                iObserver,
                                                aFunction,
                                                aStreamId,
                                                aErrorCode,
                                                aEventData );
    CleanupStack::PushL( callback );
    __ASSERT_ALWAYS( callback->Validate(), User::Leave( KErrArgument ) );
    CleanupStack::Pop( callback );

    // CActive::iActive won't tell whether User::RequestComplete has already
    // been called, so iStatus is inspected to see whether a previous call
    // to AddDeleteRequestL has already called User::RequestComplete.

    if ( iStatus == KRequestPending )
        {
        Wakeup();
        }

    iPendingCallbacks.AddLast( *callback );
    }
void NetClient::CloseSocket(int socket_fd)
{
	//FD_CLR
    lock_tcp_map_.Lock();
	std::map<int, void*>::iterator it_t = tcp_socket_map_.find(socket_fd);
	if (it_t != tcp_socket_map_.end()) 
    {
		tcp_socket_map_.erase(socket_fd);
	} 
    lock_tcp_map_.UnLock();

    lock_udp_map_.Lock();
	std::map<int, void*>::iterator it_u = udp_socket_map_.find(socket_fd);
	if (it_u != udp_socket_map_.end()) {
		udp_socket_map_.erase(socket_fd);
	}
    lock_udp_map_.UnLock();

    lock_connecting_map_.Lock();
    std::map<int, void*>::iterator iItr = connecting_map_.find(socket_fd);
    if( iItr != connecting_map_.end() )
    {
        connecting_map_.erase(socket_fd);
    }
    lock_connecting_map_.UnLock();
    
    //LogDEBUG("close scoket %d", socket_fd);
	close_socket(socket_fd);
    Wakeup();
}
示例#7
0
文件: devprog.c 项目: 8l/inferno
static void
telldbg(Progctl *ctl, char *msg)
{
	kstrcpy(ctl->msg, msg, ERRMAX);
	ctl->debugger = nil;
	Wakeup(&ctl->r);
}
示例#8
0
void
mouseproduce(Pointer m)
{
	int lastb;
	Ptrevent e;

	lock(&ptrq.lk);
	e.x = m.x;
	e.y = m.y;
	e.b = m.b;
	e.msec = osmillisec();
	lastb = mouse.b;
	mouse.x = m.x;
	mouse.y = m.y;
	mouse.b = m.b;
	mouse.msec = e.msec;
	if(!ptrq.full && lastb != m.b){
		ptrq.clicks[ptrq.wr] = e;
		if(++ptrq.wr == Nevent)
			ptrq.wr = 0;
		if(ptrq.wr == ptrq.rd)
			ptrq.full = 1;
	}
	mouse.modify = 1;
	ptrq.put++;
	unlock(&ptrq.lk);
	Wakeup(&ptrq.r);
/*	drawactive(1); */
}
int NetClient::Connect(int fd, void* context, uint32_t remote_ip, uint16_t remote_port)
{
    if (fd == INVALID_SOCKET)
    {
        LogERR("connect is error, error code: INVALID_SOCKET");
        return -1;
    }

	struct sockaddr_in remote;
	remote.sin_family = AF_INET;
	remote.sin_addr.s_addr = htonl(remote_ip);
	remote.sin_port = htons(remote_port);

	int ret = ::connect(fd, (struct sockaddr*)(&remote), sizeof (remote));
    int nError = 0;
    if (ret < 0 && !IsIgnoreSocketError(nError))
    {
        //LogERR("connect is error, error code: %d", nError);
        return -1;
    }

    lock_connecting_map_.Lock();
    connecting_map_[fd] = context;
    lock_connecting_map_.UnLock();

    Wakeup();
	return 0;
}
示例#10
0
文件: main.c 项目: 0xc0170/cox
int main()
{
    Wakeup();
    while (1)
    {
    }
}
示例#11
0
void CLibraryTipCtrl::OnShow()
{
	OnHide();	// Do the old image destroy

	BeginThread( "CtrlLibraryTip" );

	Wakeup();
}
示例#12
0
void NetClient::Stop()
{
	running_ = false;
    Wakeup();
    while( thread_.IsRunning() )
    {
        CBaseThread::Sleep(10);
    }
}
示例#13
0
文件: qio.c 项目: 8l/inferno
int
qproduce(Queue *q, void *vp, int len)
{
	Block *b;
	int dowakeup;
	uchar *p = vp;

	/* sync with qread */
	dowakeup = 0;
	lock(&q->l);

	if(q->state & Qclosed){
		unlock(&q->l);
		return -1;
	}

	/* no waiting receivers, room in buffer? */
	if(q->len >= q->limit){
		q->state |= Qflow;
		unlock(&q->l);
		return -1;
	}

	/* save in buffer */
	b = iallocb(len);
	if(b == 0){
		unlock(&q->l);
		print("qproduce: iallocb failed\n");
		return -1;
	}
	memmove(b->wp, p, len);
	b->wp += len;
	if(q->bfirst)
		q->blast->next = b;
	else
		q->bfirst = b;
	q->blast = b;
	/* b->next = 0; done by allocb() */
	q->len += BALLOC(b);
	q->dlen += BLEN(b);
	QDEBUG checkb(b, "qproduce");

	if(q->state & Qstarve){
		q->state &= ~Qstarve;
		dowakeup = 1;
	}

	if(q->len >= q->limit)
		q->state |= Qflow;
	unlock(&q->l);


	if(dowakeup)
		Wakeup(&q->rr);

	return len;
}
示例#14
0
/* is received ir-code in one of the wakeup-slots? wakeup if true */
void check_wakeups(IRMP_DATA *ir)
{
	uint8_t i, idx;
	uint8_t buf[SIZEOF_IR];
	for (i=0; i < WAKE_SLOTS; i++) {
		idx = (MACRO_DEPTH + 1) * SIZEOF_IR/2 * MACRO_SLOTS + SIZEOF_IR/2 * i;
		eeprom_restore(buf, idx);
		if (!memcmp(buf, ir, sizeof(buf)))
			Wakeup();
	}
}
示例#15
0
void Transceiver::ListenData()
{
   if (BroadcastEnable){
      Wakeup();
      buffer->setChannel(myChannel);
      timer.setStage(LISTENDATA);
      buffer->StartReceive();
   } else {
      StopListen();
   }
}
示例#16
0
文件: devlogfs.c 项目: 8l/inferno
static void
reply(Devlogfs *d)
{
	d->readp = d->readbuf;
	d->readcount = convS2M(&d->out, d->readp, d->readbufsize);
//print("reply is %d bytes\n", d->readcount);
	if (d->readcount == 0)
		panic("logfs: reply: did not fit\n");
	d->reading = 1;
	Wakeup(&d->readrendez);
}
示例#17
0
文件: devprog.c 项目: 8l/inferno
static void
dbgaddrun(Prog *p)
{
	Osenv *o;

	p->state = Pdebug;
	p->addrun = nil;
	o = p->osenv;
	if(o->rend != nil)
		Wakeup(o->rend);
	o->rend = nil;
}
示例#18
0
文件: qio.c 项目: 8l/inferno
int
qpass(Queue *q, Block *b)
{
	int dlen, len, dowakeup;

	/* sync with qread */
	dowakeup = 0;
	lock(&q->l);
	if(q->len >= q->limit){
		unlock(&q->l);
		freeblist(b);
		return -1;
	}
	if(q->state & Qclosed){
		unlock(&q->l);
		len = blocklen(b);
		freeblist(b);
		return len;
	}

	/* add buffer to queue */
	if(q->bfirst)
		q->blast->next = b;
	else
		q->bfirst = b;
	len = BALLOC(b);
	dlen = BLEN(b);
	QDEBUG checkb(b, "qpass");
	while(b->next){
		b = b->next;
		QDEBUG checkb(b, "qpass");
		len += BALLOC(b);
		dlen += BLEN(b);
	}
	q->blast = b;
	q->len += len;
	q->dlen += dlen;

	if(q->len >= q->limit/2)
		q->state |= Qflow;

	if(q->state & Qstarve){
		q->state &= ~Qstarve;
		dowakeup = 1;
	}
	unlock(&q->l);

	if(dowakeup)
		Wakeup(&q->rr);

	return len;
}
示例#19
0
文件: qio.c 项目: 8l/inferno
/*
 *  used by print() to write to a queue.  Since we may be splhi or not in
 *  a process, don't qlock.
 */
int
qiwrite(Queue *q, void *vp, int len)
{
	int n, sofar, dowakeup;
	Block *b;
	uchar *p = vp;

	dowakeup = 0;

	sofar = 0;
	do {
		n = len-sofar;
		if(n > Maxatomic)
			n = Maxatomic;

		b = iallocb(n);
		if (b == 0) {
			print("qiwrite: iallocb failed\n");
			break;
		}
		memmove(b->wp, p+sofar, n);
		b->wp += n;

		lock(&q->l);

		QDEBUG checkb(b, "qiwrite");
		if(q->bfirst)
			q->blast->next = b;
		else
			q->bfirst = b;
		q->blast = b;
		q->len += BALLOC(b);
		q->dlen += n;

		if(q->state & Qstarve){
			q->state &= ~Qstarve;
			dowakeup = 1;
		}

		unlock(&q->l);

		if(dowakeup){
			if(q->kick)
				q->kick(q->arg);
			Wakeup(&q->rr);
		}

		sofar += n;
	} while(sofar < len && (q->state & Qmsg) == 0);

	return sofar;
}
示例#20
0
void NetClient::SetSocketContext(int socket_fd, void* context, int socket_typ)
{
	if (0 == socket_typ) {
		lock_tcp_map_.Lock();
		tcp_socket_map_[socket_fd] = context;
		lock_tcp_map_.UnLock();
	} else if (1 == socket_typ) {
		lock_udp_map_.Lock();
		udp_socket_map_[socket_fd] = context;
		lock_udp_map_.UnLock();
	}
	Wakeup();
}
示例#21
0
int NetClient::SendTcpData(int socket_fd, char* data, uint32_t data_len)
{
	int sended_bytes = ::send(socket_fd, data, data_len, 0);
    if (-1 == sended_bytes)
    {
        int nError = 0;
        if (IsIgnoreSocketError(nError))
        {
            //wake up select, add tcp write event
            Wakeup();
        }
        LogDEBUG("NetClient tcp socket(%d) send error: %d", socket_fd, nError);
        return sended_bytes;
    }
    if (sended_bytes < data_len)
    {
        //wake up select, add tcp write event
        Wakeup();
    }

    return sended_bytes;
}
示例#22
0
int Processor::AddNewTask(Message *msg)
{
    Print(NOW "Processor enqueues ioreq@%p, %d:%llu:%llu\n",
          Event::Clock(), &msg->io, msg->io.cmd, msg->io.off, msg->io.count);
    if (nrs->Enqueue(msg)) {
		printf(NOW "Enqueue message failed.\n", now);
		exit(1);
	}
	
	if (poolState <= pool_IdleState) {
        Wakeup();
	}
	return 0;
}
示例#23
0
文件: main.c 项目: j1rie/IRMP_STM32
/* is received ir-code in one of the lower wakeup-slots? wakeup if true */
void check_wakeups(IRMP_DATA *ir)
{
	if(host_running())
		return;
	uint8_t i, idx;
	uint8_t buf[SIZEOF_IR];
	for (i=0; i < WAKE_SLOTS/2; i++) {
		idx = (MACRO_DEPTH + 1) * SIZEOF_IR/2 * MACRO_SLOTS + SIZEOF_IR/2 * i;
		if (!eeprom_restore(buf, idx)) {
			if (!memcmp(buf, ir, sizeof(buf)))
				Wakeup();
		}
	}
}
示例#24
0
bool Transceiver::SendKnock(bool invalid)
{
   Wakeup();
   buffer->setChannel(BroadcastChannel);
   IMFrame _frame;
   IMFrameSetup *setup=_frame.Setup();
   _frame.Reset();
   _frame.Header.Function=IMF_KNOCK;
   _frame.Header.Sequence=ksequence++;
   _frame.Header.SourceId=myId;
   PrepareSetup(*setup);
   setup->address=myHop;
   if (invalid){
     setup->salt=0;
   }
   return Send(_frame);
}
示例#25
0
void Transceiver::ListenBroadcast()
{
   if (Connected()){
     if (timer.Cycle()<_helloCycle)
       return;
//     long xKC=(timer.Cycle()-_KnockCycle);
     //if (xKC< 7)
         //return;
   } else {
     if ((timer.Cycle() & 0x4) ==0)
       return;
   }
   DBGINFO("listenBroad ");
   DBGINFO(_KnockCycle);
   Wakeup();
   DoListenBroadcast();
}
// ---------------------------------------------------------------------------
// CTurnAsyncCallback::ExecuteFirstCallback
// Handle one callback request and wait for the next one. If there are more
// callbacks, complete the asynchronous request so that RunL will soon be 
// called again. Don't call more than one callback, since upper layer
// might've deleted STUN plugin, causing CTurnAsyncCallback to be deleted too.
// For the same reason nothing is done after executing the callback.
// ---------------------------------------------------------------------------
//    
void CTurnAsyncCallback::ExecuteFirstCallback()
    {
    TTurnPluginCallbackInfo* callback = iPendingCallbacks.First();
    if ( iPendingCallbacks.IsFirst( callback ) &&
         !iPendingCallbacks.IsEmpty() )
        {
        iPendingCallbacks.Remove( *callback );

        if ( !iPendingCallbacks.IsEmpty() )
            {
            Wakeup();
            }

        callback->Execute();
        delete callback;
        }
    }
void OsclSocketServRequestList::Add(OsclSocketRequest *obj)
//add a socket request to the server (from the app thread)
{
    //Lock when adding requests to the input queue.
    Lock();

    bool empty = iAddRequests.empty();
    iAddRequests.push_back(obj);

    //signal the server thread anytime the queue goes from empty to non-empty.
    if (empty)
        Wakeup();

    //may need to interrupt a blocking select call
    iContainer->WakeupBlockingSelect();

    Unlock();
}
示例#28
0
IUnknown* CPlugins::GetPlugin(LPCTSTR pszGroup, LPCTSTR pszType)
{
	CLSID pCLSID;
	if ( ! LookupCLSID( pszGroup, pszType, pCLSID ) )
		return NULL;	// Disabled

	HRESULT hr;

	for ( int i = 0 ; ; ++i )
	{
		{
			CSingleLock oLock( &m_pSection, FALSE );
			if ( ! oLock.Lock( 500 ) ) return NULL;

			CComPtr< IUnknown > pPlugin;
			CPluginPtr* pGITPlugin = NULL;
			if ( m_pCache.Lookup( pCLSID, pGITPlugin ) )
			{
				if ( ! pGITPlugin )
					return NULL;

				if ( SUCCEEDED( hr = pGITPlugin->m_pGIT.CopyTo( &pPlugin ) ) )
					return pPlugin.Detach();

				TRACE( "Invalid plugin \"%s\"-\"%s\" %s\n", (LPCSTR)CT2A( pszGroup ), (LPCSTR)CT2A( pszType ), (LPCSTR)CT2A( Hashes::toGuid( pCLSID ) ) );
			}

			if ( i == 1 )
				break;

			m_inCLSID = pCLSID;

			// Create new one
			if ( ! BeginThread( "PluginCache" ) )
				break;	// Something really bad
		}

		Wakeup();									// Start process
		WaitForSingleObject( m_pReady, INFINITE );	// Wait for result
	}

	return NULL;
}
示例#29
0
文件: qio.c 项目: 8l/inferno
/*
 *  flush the output queue
 */
void
qflush(Queue *q)
{
	Block *bfirst;

	/* mark it */
	lock(&q->l);
	bfirst = q->bfirst;
	q->bfirst = 0;
	q->len = 0;
	q->dlen = 0;
	unlock(&q->l);

	/* free queued blocks */
	freeblist(bfirst);

	/* wake up readers/writers */
	Wakeup(&q->wr);
}
示例#30
0
文件: qio.c 项目: 8l/inferno
/*
 *  flow control, get producer going again
 *  called with q locked
 */
static void
qwakeup_unlock(Queue *q)
{
	int dowakeup = 0;

	/* if writer flow controlled, restart */
	if((q->state & Qflow) && q->len < q->limit/2){
		q->state &= ~Qflow;
		dowakeup = 1;
	}

	unlock(&q->l);

	/* wakeup flow controlled writers */
	if(dowakeup){
		if(q->kick)
			q->kick(q->arg);
		Wakeup(&q->wr);
	}
}