Ejemplo n.º 1
0
rdpTransport* transport_new(rdpContext* context)
{
	rdpTransport* transport;

	transport = (rdpTransport*) calloc(1, sizeof(rdpTransport));

	if (!transport)
		return NULL;

	transport->context = context;
	transport->settings = context->settings;

	transport->ReceivePool = StreamPool_New(TRUE, BUFFER_SIZE);

	if (!transport->ReceivePool)
		goto out_free_transport;

	/* receive buffer for non-blocking read. */
	transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0);

	if (!transport->ReceiveBuffer)
		goto out_free_receivepool;

	transport->connectedEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

	if (!transport->connectedEvent || transport->connectedEvent == INVALID_HANDLE_VALUE)
		goto out_free_receivebuffer;

	transport->blocking = TRUE;
	transport->GatewayEnabled = FALSE;
	transport->layer = TRANSPORT_LAYER_TCP;

	if (!InitializeCriticalSectionAndSpinCount(&(transport->ReadLock), 4000))
		goto out_free_connectedEvent;

	if (!InitializeCriticalSectionAndSpinCount(&(transport->WriteLock), 4000))
		goto out_free_readlock;

	return transport;
out_free_readlock:
	DeleteCriticalSection(&(transport->ReadLock));
out_free_connectedEvent:
	CloseHandle(transport->connectedEvent);
out_free_receivebuffer:
	StreamPool_Return(transport->ReceivePool, transport->ReceiveBuffer);
out_free_receivepool:
	StreamPool_Free(transport->ReceivePool);
out_free_transport:
	free(transport);
	return NULL;
}
Ejemplo n.º 2
0
DttSP_EXP void
NewKeyer (REAL freq, BOOLEAN niambic, REAL gain, REAL ramp, REAL wpm,
	  REAL SampleRate)
{
	BOOL out;
	kl = newKeyerLogic ();
	ks = newKeyerState ();
	ks->flag.iambic = niambic;
	ks->flag.revpdl = TRUE;	// depends on port wiring
	ks->flag.autospace.khar = ks->flag.autospace.word = FALSE;
	ks->flag.mdlmdB = TRUE;
	ks->flag.memory.dah = TRUE;
	ks->flag.memory.dit = TRUE;
	ks->debounce = 1;		// could be more if sampled faster
	ks->mode = MODE_B;
	ks->weight = 50;
	ks->wpm = wpm;
	iambic = niambic;
	cs_cw = &CS_CW;
	out = InitializeCriticalSectionAndSpinCount (cs_cw, 0x00000080);
	update_ok = &UPDATE_OK;
	out = InitializeCriticalSectionAndSpinCount (update_ok, 0x00000080);
#ifndef INTERLEAVED
	lring = ringb_float_create (RING_SIZE);
	rring = ringb_float_create (RING_SIZE);
#else
	lring = ringb_float_create (2 * RING_SIZE);
#endif
	sem_init (&clock_fired, 0, 0);
	sem_init (&poll_fired, 0, 0);
	sem_init (&keyer_started, 0, 0);
	if (HiPerformance)
	{
		key_poll_period = 1;
		TONE_SIZE = 48 * (int) (uni[0].samplerate / 48000.0);
	}
	else
	{
		key_poll_period = 5;
		TONE_SIZE = 240 * (int) (uni[0].samplerate / 48000.0);
	}
	//------------------------------------------------------------
	SAMP_RATE = SampleRate;
	delCWToneGen(gen);
	gen = newCWToneGen (gain, freq, ramp, ramp, TONE_SIZE, SampleRate);

	//------------------------------------------------------------
	//  if (timeSetEvent(5,1,(LPTIMECALLBACK)timer_callback,(DWORD_PTR)NULL,TIME_PERIODIC) == (MMRESULT)NULL) {
	//        fprintf(stderr,"Timer failed\n"),fflush(stderr);
	//  }
}
Ejemplo n.º 3
0
static PRStatus
NowInit(void)
{
    memset(&calibration, 0, sizeof(calibration));
    NowCalibrate();
#ifdef WINCE
    InitializeCriticalSection(&calibration.calibration_lock);
    InitializeCriticalSection(&calibration.data_lock);
#else
    InitializeCriticalSectionAndSpinCount(&calibration.calibration_lock, CALIBRATIONLOCK_SPINCOUNT);
    InitializeCriticalSectionAndSpinCount(&calibration.data_lock, DATALOCK_SPINCOUNT);
#endif
    return PR_SUCCESS;
}
Ejemplo n.º 4
0
PORT
ANB create_anb	(
	int run,
	int buffsize,
	float* in,
	float* out,
	float samplerate,
	float tau,
	float hangtime,
	float advtime,
	float backtau,
	float threshold
				)
{
	ANB a;
	a = (ANB) malloc0 (sizeof(anb));
	a->run = run;
	a->buffsize = buffsize;
	a->in = in;
	a->out = out;
	a->samplerate = samplerate;
	a->tau = tau;
	a->hangtime = hangtime;
	a->advtime = advtime;
	a->backtau = backtau;
	a->threshold = threshold;
	a->wave = (float *) malloc0 (((int)(MAX_SAMPLERATE * MAX_TAU) + 1) * sizeof(float));
	a->dline_size = (int)((MAX_TAU + MAX_ADVTIME) * MAX_SAMPLERATE) + 1;
	a->dline = (float *) malloc0 (a->dline_size * sizeof(complex));
	InitializeCriticalSectionAndSpinCount (&a->cs_update, 2500);
	initBlanker(a);
	a->legacy = (float *) malloc0 (2048 * sizeof (complex));														/////////////// legacy interface - remove
	return a;
}
Ejemplo n.º 5
0
/* global init function */
void cowInit(void) {
    int j;
    redisLog(REDIS_NOTICE, "cowInit");
    server.isBackgroundSaving = 0;
    server.cowDictCopied = NULL;
    server.cowDictConverted = NULL;
    server.cowSaveDbExt = (bkgdDbExt *)zmalloc(sizeof(bkgdDbExt)*server.dbnum);
    server.cowSaveDb = (redisDb *)zmalloc(sizeof(redisDb)*server.dbnum);

    deferSdsDelete = listCreate();
    deferObjDelete = listCreate();

    for (j = 0; j < server.dbnum; j++) {
        server.cowSaveDb[j].dict = NULL;
        server.cowSaveDb[j].expires = NULL;
        server.cowSaveDb[j].blocking_keys = NULL;
        server.cowSaveDb[j].watched_keys = NULL;
        server.cowSaveDb[j].id = j;
        server.cowSaveDbExt[j].savedType = NULL;
        server.cowSaveDbExt[j].cowType = &dbDeferDictType;
        server.cowSaveDbExt[j].readonlyType = &dbDeferDictType;
        server.cowSaveDbExt[j].dictArray = NULL;
        server.cowSaveDbExt[j].id = j;
    }

    server.cowCurIters.curDbDictIter = NULL;
    server.cowCurIters.curObjDictIter = NULL;
    server.cowCurIters.curObjListIter = NULL;
    server.cowCurIters.curObjZDictIter = NULL;
    InitializeCriticalSectionAndSpinCount(&server.cowCurIters.csMigrate, 500);

}
Ejemplo n.º 6
0
CRoom::CRoom(int roomNumber)
:roomNum(roomNumber),
 currWhoTurn(-1),
 roomState(ROOM_STATE::WAIT)
{
	InitializeCriticalSectionAndSpinCount(&playerLock, 4000);
}
Ejemplo n.º 7
0
static void
_mutex_initialize(mutex_t* mutex, const char* name, size_t length) {
	mutex->name = string_to_const(string_copy(mutex->name_buffer, 32, name, length));

#if FOUNDATION_PLATFORM_WINDOWS
	InitializeCriticalSectionAndSpinCount((CRITICAL_SECTION*)mutex->csection, 4000);
	mutex->event = CreateEvent(0, TRUE, FALSE, 0);
	atomic_store32(&mutex->waiting, 0);
#elif FOUNDATION_PLATFORM_POSIX || FOUNDATION_PLATFORM_PNACL
	mutex->pending = false;

	pthread_mutexattr_t attr;
	pthread_mutexattr_init(&attr);
	pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);

	pthread_cond_init(&mutex->cond, 0);
	pthread_mutex_init(&mutex->mutex, &attr);

	pthread_mutexattr_destroy(&attr);
#else
#  error _mutex_initialize not implemented
#endif

	mutex->lockcount = 0;
	mutex->lockedthread = 0;
}
//	===============================Select Server===============================
LSelectServer::LSelectServer()
{
#ifndef WIN32
	pthread_mutex_init(&m_mutexForCloseSessionQueue, NULL);
	pthread_mutex_init(&m_mutexForConnectToServer, NULL);
#else
	InitializeCriticalSectionAndSpinCount(&m_mutexForCloseSessionQueue, 4000);
	InitializeCriticalSectionAndSpinCount(&m_mutexForConnectToServer, 4000);
#endif
#ifdef __EPOLL_TEST_STATISTIC__
	atomic_set(&g_nSelectServerRecvPacketAllocCount, 0);
	atomic_set(&g_nSelectServerRecvPacketFreeCount, 0);
	atomic_set(&g_nSelectServerSendPacketAllocCount, 0);
	atomic_set(&g_nSelectServerSendPacketFreeCount, 0);
#endif
}
Ejemplo n.º 9
0
CHeartbeatThread::CHeartbeatThread() {
	InitializeCriticalSectionAndSpinCount(&cs_update_in_progress, 4000);
  _heartbeat_counter = 0;
  // Create events
	_m_stop_thread = CreateEvent(0, TRUE, FALSE, 0);
	_m_wait_thread = CreateEvent(0, TRUE, FALSE, 0);
}
Ejemplo n.º 10
0
Queue * QueueCreate(BOOL NoCritSec) {
    Queue * pQueue;

#ifdef DEBUG2
    DbgMsgRecord(TEXT("-> QueueCreate\n"));
#endif

    pQueue = (Queue *)AutoHeapAlloc(sizeof(Queue));

    if (pQueue == NULL) {
        AddToMessageLog(TEXT("QueueCreate: AutoHeapAlloc failed"));
        return NULL;
    }

    pQueue->pFirst = NULL;
    pQueue->pLast = NULL;    

    if (NoCritSec) {
        pQueue->lpCriticalSection = NULL;
    }
    else {
        pQueue->lpCriticalSection = (LPCRITICAL_SECTION) AutoHeapAlloc(sizeof(CRITICAL_SECTION));
        if (InitializeCriticalSectionAndSpinCount(pQueue->lpCriticalSection, 100) == 0) {
            AddToMessageLogProcFailure(TEXT("QueueCreate: InitializeCriticalSectionAndSpinCount"), GetLastError());
            QueueDelete(pQueue);
            return NULL;
        }
    }

#ifdef DEBUG2
    DbgMsgRecord(TEXT("<- QueueCreate\n"));
#endif

    return pQueue;
}
Ejemplo n.º 11
0
void __cdecl main ( )
{
    DWORD dwId=0;
    HANDLE hThread[MAXIMUM_WAIT_OBJECTS];
    DWORD dwRet=0;
    g_refCount=0;

    if(!InitializeCriticalSectionAndSpinCount(&g_cs, 4000))
    {
        return;
    }

    for(int i=0; i<MAXIMUM_WAIT_OBJECTS; i++)
    {
        hThread[i] = CreateThread(NULL, 0, ThreadProc, NULL, 0, &dwId);
        if(!hThread[i])
        {
            for(int j=0;j<i;j++)
            {   
                CloseHandle(hThread[j]);
                hThread[j]=NULL;
            }
            return;
        }
    }

    WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, hThread, TRUE, INFINITE);
    for(int i=0; i<MAXIMUM_WAIT_OBJECTS; i++)
    {
        CloseHandle(hThread[i]);
        hThread[i]=NULL;
    }
}
Ejemplo n.º 12
0
wStreamPool* StreamPool_New(BOOL synchronized, size_t defaultSize)
{
	wStreamPool* pool = NULL;

	pool = (wStreamPool*) malloc(sizeof(wStreamPool));

	if (pool)
	{
		ZeroMemory(pool, sizeof(wStreamPool));

		pool->synchronized = synchronized;
		pool->defaultSize = defaultSize;

		InitializeCriticalSectionAndSpinCount(&pool->lock, 4000);

		pool->aSize = 0;
		pool->aCapacity = 32;
		pool->aArray = (wStream**) malloc(sizeof(wStream*) * pool->aCapacity);
		ZeroMemory(pool->aArray, sizeof(wStream*) * pool->aCapacity);

		pool->uSize = 0;
		pool->uCapacity = 32;
		pool->uArray = (wStream**) malloc(sizeof(wStream*) * pool->uCapacity);
		ZeroMemory(pool->uArray, sizeof(wStream*) * pool->uCapacity);
	}

	return pool;
}
Ejemplo n.º 13
0
wQueue* Queue_New(BOOL synchronized, int capacity, int growthFactor)
{
	wQueue* queue = NULL;

	queue = (wQueue*) malloc(sizeof(wQueue));

	if (queue)
	{
		queue->head = 0;
		queue->tail = 0;
		queue->size = 0;

		queue->capacity = 32;
		queue->growthFactor = 2;

		queue->synchronized = synchronized;

		if (capacity > 0)
			queue->capacity = capacity;

		if (growthFactor > 0)
			queue->growthFactor = growthFactor;

		queue->array = (void**) malloc(sizeof(void*) * queue->capacity);
		ZeroMemory(queue->array, sizeof(void*) * queue->capacity);

		InitializeCriticalSectionAndSpinCount(&queue->lock, 4000);
		queue->event = CreateEvent(NULL, TRUE, FALSE, NULL);

		ZeroMemory(&queue->object, sizeof(wObject));
	}

	return queue;
}
Ejemplo n.º 14
0
void Player::Initialize() {
  if (initialized_ == true)
    return;

  state_ = kStateStopped;
  song_counter_ms = 0;
  auto sample_rate = audio_interface_->wave_format().nSamplesPerSec;

  {
    output_buffer_samples_ = audio_interface_->buffer_size()/sizeof(short); //size in samples
    output_buffer_length_ms_ = output_buffer_samples_ / double(sample_rate*audio_interface_->wave_format().nChannels*0.001); //400.0;//400ms
    output_buffer = new short[output_buffer_samples_]; 
    mix_buffer = new real_t[output_buffer_samples_]; 
  }

  synth_->set_sample_rate(sample_rate);
  synth_->Initialize();

  thread_msg = 0;
  InitializeCriticalSection(&vis_cs);
  InitializeCriticalSectionAndSpinCount(&cs,0x100);
  player_event = CreateEvent(NULL,FALSE,FALSE,NULL);
  thread_handle = CreateThread(nullptr,0,static_cast<LPTHREAD_START_ROUTINE>(PlayThread),this,0,(LPDWORD)&thread_id);//CREATE_SUSPENDED
  if (thread_handle != nullptr) {
    SetThreadPriority(thread_handle,THREAD_PRIORITY_ABOVE_NORMAL);
  }

  initialized_ = true;
}
Ejemplo n.º 15
0
BOOL InitTCPServer(unsigned short nPort)
{
	for(int i=0; i<sizeof(g_csClients)/sizeof(g_csClients[0]); i++) {
		InitializeCriticalSectionAndSpinCount(&g_csClients[i], 0x80000400);
	}

	mem_pool = AllocIoBufferPool(MAX_UP_LEN, 2048, MAX_DOWN_LEN, 1024);
	if(!mem_pool) {
		return(FALSE);
	}

	SOCKADDR_IN sain;
	ZeroMemory(&sain, sizeof(sain));
	sain.sin_family = AF_INET;
	sain.sin_port = htons(nPort);
	TCP_EP_HANDLER conn_handler = {
		OnUserConnect,
		OnUserDisconnect,
		OnUserData,
		NULL
	};
	TCP_OPTION tcpopt;
	GetDefTCPOpt(&tcpopt);
	tcpopt.sndbuf = 0;
	tcpopt.reuse_addr = TRUE;
	tcpopt.keep_alive = TRUE;
	tcpopt.nodelay = TRUE;
	end_point = RegisterTcpEndPoint(&sain, &conn_handler, &tcpopt, mem_pool, NULL);

	return(end_point!=NULL);
}
Ejemplo n.º 16
0
static INLINE Bool
MXUserCreateInternal(MXUserCondVar *condVar)  // IN/OUT:
{
   Bool success;

   if (MXUserNativeCVSupported()) {
      ASSERT(pInitializeConditionVariable);
      (*pInitializeConditionVariable)(&condVar->x.condObject);
      success = TRUE;
   } else {
      if (InitializeCriticalSectionAndSpinCount(&condVar->x.compat.condVarLock,
                                                0x80000400) == 0) {
         success = FALSE;
      } else {
         condVar->x.compat.numWaiters = 0;
         condVar->x.compat.numForRelease = 0;

         condVar->x.compat.signalEvent = CreateEvent(NULL,  // no security
                                                     TRUE,  // manual-reset
                                                     FALSE, // non-signaled
                                                     NULL); // unnamed

         success = (condVar->x.compat.signalEvent != NULL);

         if (!success) {
            DeleteCriticalSection(&condVar->x.compat.condVarLock);
         }
      }
   }

   return success;
}
Ejemplo n.º 17
0
rdpChannels* freerdp_channels_new(freerdp* instance)
{
	rdpChannels* channels;
	channels = (rdpChannels*) calloc(1, sizeof(rdpChannels));

	if (!channels)
		return NULL;

	if (!InitializeCriticalSectionAndSpinCount(&channels->channelsLock, 4000))
		goto error;

	channels->instance = instance;
	channels->queue = MessageQueue_New(NULL);

	if (!channels->queue)
		goto error;

	channels->openHandles = HashTable_New(TRUE);

	if (!channels->openHandles)
		goto error;

	return channels;
error:
	freerdp_channels_free(channels);
	return NULL;
}
Ejemplo n.º 18
0
cDxCapture::cDxCapture() :
	m_width(0)
	, m_height(0)
	, m_cameraIndex(0)
	, m_pFrameBuffer(NULL)
	, m_frameBufferSize(0)
	, m_pCloneFrameBuffer(NULL)
	, m_isThreadMode(false)
	, m_threadLoop(true)
	, m_isUpdateBuffer(false)
	, m_isUnpluggedInit(false)
{
	m_dwGraphRegister = 0;
	m_pVW = NULL;
	m_pMC = NULL;
	m_pME = NULL;
	m_pGraph = NULL;
	m_pCapture = NULL;
	m_pGrabberF = NULL;
	m_pGrabber = NULL;
	m_pNullF = NULL;
	m_psCurrent = STOPPED;
	ZeroMemory(&m_mt, sizeof(m_mt));

	InitializeCriticalSectionAndSpinCount(&m_criticalSection, 0x00000400);

}
Ejemplo n.º 19
0
rdpChannels* freerdp_channels_new(void)
{
	rdpChannels* channels;

	channels = (rdpChannels*) calloc(1, sizeof(rdpChannels));
	if (!channels)
		return NULL;

	channels->queue = MessageQueue_New(NULL);
	if (!channels->queue)
		goto error_queue;

	if (!g_OpenHandles)
	{
		g_OpenHandles = HashTable_New(TRUE);
		if (!g_OpenHandles)
			goto error_open_handles;

		if (!InitializeCriticalSectionAndSpinCount(&g_channels_lock, 4000))
			goto error_open_handles;
	}

	return channels;

error_open_handles:
	MessageQueue_Free(channels->queue);
error_queue:
	free(channels);
	return NULL;
}
Ejemplo n.º 20
0
wObjectPool* ObjectPool_New(BOOL synchronized)
{
	wObjectPool* pool = NULL;

	pool = (wObjectPool*) calloc(1, sizeof(wObjectPool));

	if (pool)
	{
		pool->capacity = 32;
		pool->size = 0;
		pool->array = (void**) calloc(pool->capacity, sizeof(void*));
		if (!pool->array)
		{
			free(pool);
			return NULL;
		}
		pool->synchronized = synchronized;

		if (pool->synchronized)
			InitializeCriticalSectionAndSpinCount(&pool->lock, 4000);

	}

	return pool;
}
Ejemplo n.º 21
0
/*
    Static version just for mprAlloc which needs locks that don't allocate memory.
 */
PUBLIC MprSpin *mprInitSpinLock(MprSpin *lock)
{
#if USE_MPR_LOCK
    mprInitLock(&lock->cs);

#elif MACOSX
    lock->cs = OS_SPINLOCK_INIT;

#elif ME_UNIX_LIKE && ME_COMPILER_HAS_SPINLOCK
    pthread_spin_init(&lock->cs, 0);

#elif ME_UNIX_LIKE
    pthread_mutexattr_t attr;
    pthread_mutexattr_init(&attr);
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE_NP);
    pthread_mutex_init(&lock->cs, &attr);
    pthread_mutexattr_destroy(&attr);

#elif ME_WIN_LIKE && !ME_DEBUG && CRITICAL_SECTION_NO_DEBUG_INFO && ME_64 && _WIN32_WINNT >= 0x0600
    InitializeCriticalSectionEx(&lock->cs, ME_MPR_SPIN_COUNT, CRITICAL_SECTION_NO_DEBUG_INFO);
    lock->freed = 0;

#elif ME_WIN_LIKE
    InitializeCriticalSectionAndSpinCount(&lock->cs, ME_MPR_SPIN_COUNT);
    lock->freed = 0;

#elif VXWORKS
    lock->cs = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE);
#endif /* VXWORKS */

#if ME_DEBUG
    lock->owner = 0;
#endif
    return lock;
}
Ejemplo n.º 22
0
DELAY create_delay (int run, int size, float* in, float* out, int rate, float tdelta, float tdelay)
{
	DELAY a = (DELAY) malloc0 (sizeof (delay));
	a->run = run;
	a->size = size;
	a->in = in;
	a->out = out;
	a->rate = rate;
	a->tdelta = tdelta;
	a->tdelay = tdelay;
	a->L = (int)(0.5 + 1.0 / (a->tdelta * (float)a->rate));
	a->ft = 0.45 / (float)a->L;
	a->ncoef = (int)(60.0 / a->ft);
	a->ncoef = (a->ncoef / a->L + 1) * a->L;
	a->cpp = a->ncoef / a->L;
	a->phnum = (int)(0.5 + a->tdelay / a->tdelta);
	a->snum = a->phnum / a->L;
	a->phnum %= a->L;
	a->idx_in = 0;
	a->adelta = 1.0 / (a->rate * a->L);
	a->adelay = a->adelta * (a->snum * a->L + a->phnum);
	a->h = fir_bandpass (a->ncoef,-a->ft, +a->ft, 1.0, 1, 0, (float)a->L);	
	a->rsize = a->cpp + (WSDEL - 1);
	a->ring = (float *) malloc0 (a->rsize * sizeof (complex));
	InitializeCriticalSectionAndSpinCount ( &a->cs_update, 2500 );
	return a;
}
Ejemplo n.º 23
0
rdpShadowSurface* shadow_surface_new(rdpShadowServer* server, int x, int y, int width, int height)
{
	rdpShadowSurface* surface;

	surface = (rdpShadowSurface*) calloc(1, sizeof(rdpShadowSurface));

	if (!surface)
		return NULL;

	surface->server = server;

	surface->x = x;
	surface->y = y;
	surface->width = width;
	surface->height = height;
	surface->scanline = (surface->width + (surface->width % 4)) * 4;

	surface->data = (BYTE*) calloc(1, surface->scanline * surface->height);
	if (!surface->data)
	{
		free (surface);
		return NULL;
	}

	if (!InitializeCriticalSectionAndSpinCount(&(surface->lock), 4000))
	{
		free (surface->data);
		free (surface);
		return NULL;
	}

	region16_init(&(surface->invalidRegion));

	return surface;
}
Ejemplo n.º 24
0
nsresult
TimeStamp::Startup()
{
  // Decide which implementation to use for the high-performance timer.

  InitializeCriticalSectionAndSpinCount(&sTimeStampLock, kLockSpinCount);

  LARGE_INTEGER freq;
  BOOL QPCAvailable = ::QueryPerformanceFrequency(&freq);
  if (!QPCAvailable) {
    // No Performance Counter.  Fall back to use GetTickCount.
    sFrequencyPerSec = 1;
    sFallBackToGTC = true;
    InitResolution();

    LOG(("TimeStamp: using GetTickCount"));
    return NS_OK;
  }

  sFrequencyPerSec = freq.QuadPart;

  ULONGLONG qpc = PerformanceCounter();
  sLastCalibrated = TickCount64(::GetTickCount());
  sSkew = qpc - ms2mt(sLastCalibrated);

  InitThresholds();
  InitResolution();

  LOG(("TimeStamp: initial skew is %1.2fms", mt2ms_d(sSkew)));

  return NS_OK;
}
Ejemplo n.º 25
0
static struct accepting_socket *
new_accepting_socket(struct evconnlistener_iocp *lev, int family)
{
	struct accepting_socket *res;
	int addrlen;
	int buflen;

	if (family == AF_INET)
		addrlen = sizeof(struct sockaddr_in);
	else if (family == AF_INET6)
		addrlen = sizeof(struct sockaddr_in6);
	else
		return NULL;
	buflen = (addrlen+16)*2;

	res = mm_calloc(1,sizeof(struct accepting_socket)-1+buflen);
	if (!res)
		return NULL;

	event_overlapped_init(&res->overlapped, accepted_socket_cb);
	res->s = INVALID_SOCKET;
	res->lev = lev;
	res->buflen = buflen;
	res->family = family;

	event_deferred_cb_init(&res->deferred,
		accepted_socket_invoke_user_cb, res);

	InitializeCriticalSectionAndSpinCount(&res->lock, 1000);

	return res;
}
Ejemplo n.º 26
0
			mutex::mutex()
			{
				#if defined(EA_PLATFORM_MICROSOFT)
					static_assert(sizeof(mMutexBuffer) == sizeof(CRITICAL_SECTION), "mMutexBuffer size failure");
					//static_assert(EA_ALIGN_OF(mMutexBuffer) >= EA_ALIGN_OF(CRITICAL_SECTION), "mMutexBuffer alignment failure"); // Enabling this causes the VS2012 compiler to crash.

					#if !defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0403)
						InitializeCriticalSection((CRITICAL_SECTION*)mMutexBuffer);
					#elif !EA_WINAPI_FAMILY_PARTITION(EA_WINAPI_PARTITION_DESKTOP)
						BOOL result = InitializeCriticalSectionEx((CRITICAL_SECTION*)mMutexBuffer, 10, 0);
						EASTL_ASSERT(result != 0); EA_UNUSED(result);
					#else
						BOOL result = InitializeCriticalSectionAndSpinCount((CRITICAL_SECTION*)mMutexBuffer, 10);
						EASTL_ASSERT(result != 0); EA_UNUSED(result);
					#endif

				#elif defined(EA_PLATFORM_POSIX)
					pthread_mutexattr_t attr;

					pthread_mutexattr_init(&attr);
					pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_PRIVATE); 
					pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
					pthread_mutex_init(&mMutex, &attr);
					pthread_mutexattr_destroy(&attr);
				#endif
			}
Ejemplo n.º 27
0
wMessageQueue* MessageQueue_New(const wObject *callback)
{
	wMessageQueue* queue = NULL;

	queue = (wMessageQueue*) malloc(sizeof(wMessageQueue));

	if (queue)
	{
		queue->head = 0;
		queue->tail = 0;
		queue->size = 0;

		queue->capacity = 32;
		queue->array = (wMessage*) malloc(sizeof(wMessage) * queue->capacity);
		ZeroMemory(queue->array, sizeof(wMessage) * queue->capacity);

		InitializeCriticalSectionAndSpinCount(&queue->lock, 4000);
		queue->event = CreateEvent(NULL, TRUE, FALSE, NULL);

		if (callback)
			queue->object = *callback;
		else
			ZeroMemory(&queue->object, sizeof(queue->object));
	}

	return queue;
}
Ejemplo n.º 28
0
wLogAppender* WLog_Appender_New(wLog* log, DWORD logAppenderType)
{
	wLogAppender* appender = NULL;

	if (logAppenderType == WLOG_APPENDER_CONSOLE)
	{
		appender = (wLogAppender*) WLog_ConsoleAppender_New(log);
	}
	else if (logAppenderType == WLOG_APPENDER_FILE)
	{
		appender = (wLogAppender*) WLog_FileAppender_New(log);
	}
	else if (logAppenderType == WLOG_APPENDER_BINARY)
	{
		appender = (wLogAppender*) WLog_BinaryAppender_New(log);
	}

	if (!appender)
		appender = (wLogAppender*) WLog_ConsoleAppender_New(log);

	appender->Layout = WLog_Layout_New(log);

	InitializeCriticalSectionAndSpinCount(&appender->lock, 4000);

	return appender;
}
Ejemplo n.º 29
0
wCountdownEvent* CountdownEvent_New(DWORD initialCount)
{
	wCountdownEvent* countdown = NULL;

	if (!(countdown = (wCountdownEvent*) calloc(1, sizeof(wCountdownEvent))))
		return NULL;

	countdown->count = initialCount;
	countdown->initialCount = initialCount;

	if (!InitializeCriticalSectionAndSpinCount(&countdown->lock, 4000))
		goto fail_critical_section;

	if (!(countdown->event = CreateEvent(NULL, TRUE, FALSE, NULL)))
		goto fail_create_event;

	if (countdown->count == 0)
		if (!SetEvent(countdown->event))
			goto fail_set_event;

	return countdown;

fail_set_event:
	CloseHandle(countdown->event);
fail_create_event:
	DeleteCriticalSection(&countdown->lock);
fail_critical_section:
	free(countdown);

	return NULL;
}
Ejemplo n.º 30
0
int main()
{
    InitializeCriticalSectionAndSpinCount(&g_cs,4000);
    InitializeSRWLock(&g_SRWlock);
    g_hMutex = CreateMutex(NULL,FALSE,NULL);
	for (int i = 1; i < 17; i *= 2)
    {
        std::cout << std::left << std::setw(16) << "Volatile Read ";
        WaitFuncComplete(i,FuncVolatileRead);
        std::cout << std::setw(16) << "Volatile Write ";
        WaitFuncComplete(i,FuncVolatileWrite);
        std::cout << std::setw(16) << "Interlock ";
        WaitFuncComplete(i,FuncInterlock);
        std::cout << std::setw(16) << "CriticalSection ";
        WaitFuncComplete(i,FuncCriticalSection);
        std::cout << std::setw(16) << "SRWLock Read ";
        WaitFuncComplete(i,FuncSRWLockRead);
        std::cout << std::setw(16) << "SRWLock Write ";
        WaitFuncComplete(i,FuncSRWLockWrite);
        std::cout << std::setw(16) << "Mutex ";
        WaitFuncComplete(i,FuncMutex);
        std::cout << std::endl;
	}
    DeleteCriticalSection(&g_cs);
    CloseHandle(g_hMutex);
    getchar();
    return 0;
}