コード例 #1
0
OsStatus MpOss::attachReader()
{
   OsStatus ret = OS_FAILED;

   UtlBoolean threadSleep = (mStReader == FALSE) && (mStWriter == FALSE);

   if (!((mReader == NULL) || (mStReader == TRUE)))
   {
      assert(mbReadCap == TRUE);
      ret = setSampleRate(mReader->mSamplesPerSec, mReader->mSamplesPerFrame);
      if (ret == OS_SUCCESS) {
         mStReader = TRUE;

         if (threadSleep) 
         {
            threadWakeUp();
         }
         else
         {
            threadIoStatusChanged();
         }
      }
   }
   return ret;
}
コード例 #2
0
ファイル: worker_pool.c プロジェクト: zhangjinde/z
int workerPoolSend(struct context *ctx, 
					uint32_t from,
					uint32_t to,
					uint32_t session,
					uint32_t type,
					void *data,
					size_t sz,
					uint32_t ud) {

	char from_name[32];
	snprintf(from_name, 32, "c_%d", from);
	if (from == 0) {
		if (ctx) {
			from = ctx->id;
			snprintf(from_name, 32, "%s", ctx->name);
		}
	}

	if (to == 0) {
		return -1;
	}

	struct context *toctx = ctxMgrGetContext(to);
	if (toctx == NULL) {
		fprintf(stderr, "send to service(%d) type(%d),not found service!\n", to, type);
		if (data) {
			zfree(data);
		}
		return -1;
	}

	struct message msg;
	msg.from = from;

	if (type & MSG_TYPE_NEWSESSION) {
		msg.session = contextNewsession(ctx);
	} else {
		msg.session = session;
	}

	msg.type = type;
	msg.ud = ud;
	msg.sz = sz;
	msg.data = data;
	
	if (!messageQueuePush(toctx->queue, &msg)) {
		fprintf(stderr, "context(%d) queue full, size(%d)!\n", 
							toctx->id,
							messageQueueSize(toctx->queue));

		assert(0);
		ctxMgrReleaseContext(toctx);
		return -1;
	}
	
	logInfo("from(%s) to(%s) type(%X)", from_name, toctx->name);
	if (CAS(&toctx->inGlobal, 0, 1)) {
		contextQueuePush(M->queue, toctx);	
		threadWakeUp();
	} else {
		ctxMgrReleaseContext(toctx);
	}
	return msg.session;
}