Пример #1
0
static int server_create(
    IN const struct server_info *info,
    OUT nfs41_server **server_out)
{
    int status = NO_ERROR;
    nfs41_server *server;

    server = calloc(1, sizeof(nfs41_server));
    if (server == NULL) {
        status = GetLastError();
        eprintf("failed to allocate server %s\n", info->owner);
        goto out;
    }

    StringCchCopyA(server->scope, NFS4_OPAQUE_LIMIT, info->scope);
    StringCchCopyA(server->owner, NFS4_OPAQUE_LIMIT, info->owner);
    InitializeSRWLock(&server->addrs.lock);
    nfs41_superblock_list_init(&server->superblocks);

    status = nfs41_name_cache_create(&server->name_cache);
    if (status) {
        eprintf("nfs41_name_cache_create() failed with %d\n", status);
        goto out_free;
    }
out:
    *server_out = server;
    return status;

out_free:
    free(server);
    server = NULL;
    goto out;
}
Пример #2
0
int _tmain(int argc, _TCHAR* argv[]) {
	
   for (int nThreads = 1; nThreads <= 4; nThreads *= 2) {
      MeasureConcurrentOperation(TEXT("Volatile Read"), nThreads, VolatileReadCallback);
		MeasureConcurrentOperation(TEXT("Volatile Write"), nThreads, VolatileWriteCallback);
		MeasureConcurrentOperation(TEXT("Interlocked Increment"), nThreads, InterlockedIncrementCallback);

		// Prepare the critical section
		InitializeCriticalSection(&g_cs);
		MeasureConcurrentOperation(TEXT("Critical Section"), nThreads, CriticalSectionCallback);
		// Don't forget to cleanup
		DeleteCriticalSection(&g_cs);

      // Prepare the Slim Reader/Writer lock
		InitializeSRWLock(&g_srwLock);
		MeasureConcurrentOperation(TEXT("SRWLock Read"), nThreads, SRWLockReadCallback);
		MeasureConcurrentOperation(TEXT("SRWLock Write"), nThreads, SRWLockWriteCallback);
		// NOTE: You can't cleanup a Slim Reader/Writer lock

		// Prepare the mutex
		g_hMutex = CreateMutex(NULL, false, NULL);
		MeasureConcurrentOperation(TEXT("Mutex"), nThreads, MutexCallback);
		CloseHandle(g_hMutex);
		_tprintf(TEXT("\n"));
	}   

	return(0);
}
Пример #3
0
void ReadWriteLock::Initialize()
{
	if (mLock.Ptr==nullptr)
	{
		InitializeSRWLock(&mLock);
	}
}
Пример #4
0
/* session creation */
static int session_alloc(
    IN nfs41_client *client,
    OUT nfs41_session **session_out)
{
    nfs41_session *session;
    int status = NO_ERROR;

    session = calloc(1, sizeof(nfs41_session));
    if (session == NULL) {
        status = GetLastError();
        goto out;
    }
    session->client = client;
    session->renew_thread = INVALID_HANDLE_VALUE;
    session->isValidState = FALSE;

    InitializeCriticalSection(&session->table.lock);
    InitializeConditionVariable(&session->table.cond);

    init_slot_table(&session->table);

    //initialize session lock
    InitializeSRWLock(&client->session_lock);

    /* initialize the back channel */
    nfs41_callback_session_init(session);

    *session_out = session;
out:
    return status;
}
Пример #5
0
void
InitializeForClients()
{
	InitializeSRWLock(&srwClientsLock);

	clientsHeader.next = NULL;
}
IN_PROCESS_APPLICATION::IN_PROCESS_APPLICATION(
    IHttpServer*        pHttpServer,
    ASPNETCORE_CONFIG*  pConfig) :
    APPLICATION(pHttpServer, pConfig),
    m_pHttpServer(pHttpServer),
    m_ProcessExitCode(0),
    m_hLogFileHandle(INVALID_HANDLE_VALUE),
    m_hErrReadPipe(INVALID_HANDLE_VALUE),
    m_hErrWritePipe(INVALID_HANDLE_VALUE),
    m_dwStdErrReadTotal(0),
    m_fDoneStdRedirect(FALSE),
    m_fBlockCallbacksIntoManaged(FALSE),
    m_fInitialized(FALSE),
    m_fShutdownCalledFromNative(FALSE),
    m_fShutdownCalledFromManaged(FALSE),
    m_srwLock()
{
    // is it guaranteed that we have already checked app offline at this point?
    // If so, I don't think there is much to do here.
    DBG_ASSERT(pHttpServer != NULL);
    DBG_ASSERT(pConfig != NULL);
    InitializeSRWLock(&m_srwLock);

    // TODO we can probably initialized as I believe we are the only ones calling recycle.
    m_status = APPLICATION_STATUS::STARTING;
}
Пример #7
0
BOOL Dlg_OnInitDialog(HWND hWnd, HWND hWndFocus, LPARAM lParam) {

   chSETDLGICONS(hWnd, IDI_QUEUE);

   g_hWnd = hWnd; // Used by client/server threads to show status

   // Prepare the SRWLock to be used
   InitializeSRWLock(&g_srwLock);

   // Prepare the condition variables to be used
   InitializeConditionVariable(&g_cvReadyToConsume);
   InitializeConditionVariable(&g_cvReadyToProduce);

   // Will be set to TRUE in order to end threads
   g_fShutdown = FALSE;

   // Create the writer threads
   DWORD dwThreadID;
   for (int x = 0; x < 4; x++)
      g_hThreads[g_nNumThreads++] = 
         chBEGINTHREADEX(NULL, 0, WriterThread, (PVOID) (INT_PTR) x, 
            0, &dwThreadID);

   // Create the reader threads
   for (int x = 0; x < 2; x++)
      g_hThreads[g_nNumThreads++] = 
         chBEGINTHREADEX(NULL, 0, ReaderThread, (PVOID) (INT_PTR) x, 
            0, &dwThreadID);

   return(TRUE);
}
Пример #8
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;
}
Пример #9
0
/* windows slim SRWLOCK functions */
int  rwmutex_init(XQ_rwmutex_t *m)
{
#if _WIN32_WINNT >= 0x0700
    InitializeSRWLock(m);
#endif
    return 0;

}
Пример #10
0
int belle_sip_mutex_init(belle_sip_mutex_t *mutex, void *attr) {
#ifdef BELLE_SIP_WINDOWS_DESKTOP
	*mutex = CreateMutex(NULL, FALSE, NULL);
#else
	InitializeSRWLock(mutex);
#endif
	return 0;
}
Пример #11
0
PLATAPI void plat_rwlock_init(plat_thread_rwlock_t* rwlock) {
	InitializeSRWLock(&rwlock->tl_slim_rwlock);

	/* Because WinAPI provides two functions to release lock,
	 * save mode of lock acquiring */
	rwlock->tl_mode_key = TlsAlloc();
	assert(rwlock->tl_mode_key != TLS_OUT_OF_INDEXES);
}
Пример #12
0
static void cache_init(
    struct idmap_cache *cache,
    const struct cache_ops *ops)
{
    list_init(&cache->head);
    cache->ops = ops;
    InitializeSRWLock(&cache->lock);
}
Пример #13
0
NET_USE_NAMESPACE

#if defined (WIN32)

RWMutex::RWMutex() : _readmode(true)
{
  InitializeSRWLock(&_mutex);
}
Пример #14
0
struct os_lock* os_createLock(void)
{
   struct os_lock* lock = malloc(sizeof(struct os_lock));
   if (lock)
   {
      InitializeSRWLock(&lock->handle);
   }
   return lock;
}
Пример #15
0
int __bctbx_WIN_mutex_init(bctbx_mutex_t *mutex, void *attr)
{
#ifdef BCTBX_WINDOWS_DESKTOP
	*mutex=CreateMutex(NULL, FALSE, NULL);
#else
	InitializeSRWLock(mutex);
#endif
	return 0;
}
Пример #16
0
RWLock::RWLock()
{
#if defined(OVR_CAPTURE_WINDOWS)
    InitializeSRWLock(&m_lock);
#elif defined(OVR_CAPTURE_POSIX)
    pthread_rwlock_init(&m_lock, NULL);
#else
#error Unknown Platform!
#endif
}
Пример #17
0
int
pthread_rwlock_init(pthread_rwlock_t *rwlock,
    const pthread_rwlockattr_t *ignored)
{
	ignored = ignored;			/* Unused variable. */
	InitializeSRWLock(&rwlock->rwlock);
	rwlock->exclusive_locked = 0;

	return (0);
}
Пример #18
0
int
CPacBioUtility::CreateMutexes(void)
{
if(m_bMutexesCreated)
	return(eBSFSuccess);

#ifdef _WIN32
InitializeSRWLock(&m_hRwLock);
#else
if(pthread_rwlock_init (&m_hRwLock,NULL)!=0)
	{
	gDiagnostics.DiagOut(eDLFatal,gszProcName,"Fatal: unable to create rwlock");
	return(eBSFerrInternal);
	}
#endif

#ifdef _WIN32
if((m_hMtxIterReads = CreateMutex(NULL,false,NULL))==NULL)
	{
#else
if(pthread_mutex_init (&m_hMtxIterReads,NULL)!=0)
	{
	pthread_rwlock_destroy(&m_hRwLock);
#endif
	gDiagnostics.DiagOut(eDLFatal,gszProcName,"Fatal: unable to create mutex");
	return(eBSFerrInternal);
	}

m_bMutexesCreated = true;
return(eBSFSuccess);
}

void
CPacBioUtility::DeleteMutexes(void)
{
if(!m_bMutexesCreated)
	return;
#ifdef _WIN32
CloseHandle(m_hMtxIterReads);
#else
pthread_mutex_destroy(&m_hMtxIterReads);
pthread_rwlock_destroy(&m_hRwLock);
#endif
m_bMutexesCreated = false;
}

void
CPacBioUtility::AcquireSerialise(void)
{
#ifdef _WIN32
WaitForSingleObject(m_hMtxIterReads,INFINITE);
#else
pthread_mutex_lock(&m_hMtxIterReads);
#endif
}
Пример #19
0
  ThreadController::ThreadController( LPTHREAD_START_ROUTINE threadProc,
  LPVOID threadArg ): mThreadProc( threadProc ), mThreadArg( threadArg ),
  mStartEvent( NULL ), mStopEvent( NULL ), mThread( NULL ), mThreadID( 0 )
  {
    InitializeSRWLock( &rwlThread );

    mStartEvent = CreateEventW( NULL, TRUE, FALSE, NULL );
    mStopEvent = CreateEventW( NULL, TRUE, FALSE, NULL );

    if ( !mStartEvent || !mStopEvent )
      EXCEPT( L"Couldn't create thread signal events" );
  }
Serial_Port::Serial_Port(char *&uart_name_, int &baudrate_)
{
	// Initialize attributes
	debug  = false;
	hComm     = NULL;
	status = SERIAL_PORT_CLOSED;

	LPportname = uart_name_;
	baudrate  = baudrate_;

	InitializeSRWLock(&lock);  // Init SRWLock
}
Пример #21
0
/* 读写锁 */
EXEC_RETURN rwlock_Create(RWLOCK* rwlock){
#if defined(WIN32) || defined(_WIN64)
	rwlock->type = 0;
	InitializeSRWLock(&rwlock->lock);
	return EXEC_SUCCESS;
#else
	int res;
	res = pthread_rwlock_init(rwlock,NULL);
	errno = res;
	return res ? EXEC_ERROR:EXEC_SUCCESS;
#endif
}
Пример #22
0
RWLock::RWLock(const char* aName)
  : BlockingResourceBase(aName, eMutex)
#ifdef DEBUG
  , mOwningThread(nullptr)
#endif
{
#ifdef XP_WIN
  InitializeSRWLock(NativeHandle(mRWLock));
#else
  MOZ_RELEASE_ASSERT(pthread_rwlock_init(NativeHandle(mRWLock), nullptr) == 0,
                     "pthread_rwlock_init failed");
#endif
}
Пример #23
0
int TRI_InitMutex (TRI_mutex_t* mutex) {
  // as of VS2013, exclusive SRWLocks tend to be faster than native mutexes
#if TRI_WINDOWS_VISTA_LOCKS
  mutex->_mutex = CreateMutex(nullptr, FALSE, nullptr);

  if (mutex->_mutex == nullptr) {
    LOG_FATAL_AND_EXIT("cannot create the mutex");
  }
#else
  InitializeSRWLock(&mutex->_mutex);
#endif
  return TRI_ERROR_NO_ERROR;
}
Пример #24
0
void SectionLockerGlobal::Initialize()
{
    if(m_Initialized)
        return;

    // Destroy previous data if any existed
    memset(m_Locks, 0, sizeof(m_Locks));

    for(int i = 0; i < ARRAYSIZE(m_Locks); i++)
        InitializeSRWLock(&m_Locks[i]);

    m_Initialized = true;
}
Пример #25
0
DWORD QueueInitialize (QUEUE_OBJECT *q, DWORD msize, DWORD nmsgs)
{
    /* Initialize queue, including its mutex and events */
    /* Allocate storage for all messages. */

    if ((q->msgArray = calloc (nmsgs, msize)) == NULL) return 1;
    q->qFirst = q->qLast = 0;
    q->qSize = nmsgs;

    InitializeSRWLock(&q->qGuard);
    InitializeConditionVariable(&q->qNe);
    InitializeConditionVariable(&q->qNf);
    return 0; /* No error */
}
Пример #26
0
int pthread_rwlock_init(pthread_rwlock_t *l, pthread_rwlockattr_t *a)
{
  (void) a;
#ifndef PTHREAD_WIN_XP_SYNC	
  InitializeSRWLock(l);
#else
  l->sema_read = CreateSemaphore(NULL,0,MAX_INT,NULL);
  l->sema_write = CreateSemaphore(NULL,0,MAX_INT,NULL);
  l->mutex = CreateMutex(NULL,FALSE,NULL);
  l->reader_count = 0;
  l->nb_waiting_reader = 0;
  l->nb_waiting_writer = 0;
#endif
  return 0;
}
PACL_LIST acl_init(){
	_SHM_LOCKDEF lockdef;
	ZeroMemory(&acl_shm,sizeof(acl_shm));
	acl_shm.len = 2048*sizeof(ACL_ENTRY)+sizeof(int);
	_tcscpy(acl_shm.filename,SHM_ACL_NAME);
	_tcscpy(lockdef.lockname,SHM_LOCK_NONE);
	_tcscpy(lockdef.eackname,SHM_LOCK_NONE);
	_tcscpy(lockdef.esndname,SHM_LOCK_NONE);
	if(FAILED(shm_init(&acl_shm,&lockdef))){
		DEBUG_PRINT_LASTERROR("[ACL]Fail to open shared memory: %s\n");
		return NULL;
	}
	PACL_LIST ret = (PACL_LIST)acl_shm.data;
	InitializeSRWLock(&ret->lock);
	return ret;
}
Пример #28
0
RWLock* RWLockCreate() {
	RWLock *lock = NULL;
	lock = (RWLock*) malloc(sizeof(RWLock));
	if (!lock)
		return lock;
#if RWLOCK_VENDOR == WINDOWS_SRW_RWLOCK_VENDOR
	InitializeSRWLock(&lock->_M_locker);
#elif RWLOCK_VENDOR == PTHREAD_RWLOCK_VENDOR
	if (pthread_rwlock_init(&lock->_M_locker, NULL) == 0)
		return lock;
	free(lock);
	lock = NULL;
#elif RWLOCK_VENDOR == WINDOWS_SIM_RWLOCK_VENDOR
	// TODO
#endif
    return lock;
}
Пример #29
0
Файл: thread.c Проект: Gd58/MCF
void *MCF_CRT_TlsAllocKey(void (*pfnCallback)(intptr_t)){
	TlsKey *const pKey = malloc(sizeof(TlsKey));
	if(!pKey){
		SetLastError(ERROR_NOT_ENOUGH_MEMORY);
		return nullptr;
	}
	InitializeSRWLock(&(pKey->srwLock));
	pKey->pfnCallback = pfnCallback;
	pKey->pLastByKey  = nullptr;

	AcquireSRWLockExclusive(&g_csKeyMutex);
	{
		MCF_AvlAttach(&g_pavlKeys, (MCF_AvlNodeHeader *)pKey, &KeyComparatorNodes);
	}
	ReleaseSRWLockExclusive(&g_csKeyMutex);

	return pKey;
}
Пример #30
0
void heap_init()
{
	log_info("heap subsystem initializating...\n");
	heap = mm_static_alloc(sizeof(struct heap_data));
	InitializeSRWLock(&heap->rw_lock);
	heap->pools[0].objsize = 16;		heap->pools[0].first = NULL;
	heap->pools[1].objsize = 32;		heap->pools[1].first = NULL;
	heap->pools[2].objsize = 64;		heap->pools[2].first = NULL;
	heap->pools[3].objsize = 128;		heap->pools[3].first = NULL;
	heap->pools[4].objsize = 256;		heap->pools[4].first = NULL;
	heap->pools[5].objsize = 512;		heap->pools[5].first = NULL;
	heap->pools[6].objsize = 1024;		heap->pools[6].first = NULL;
	heap->pools[7].objsize = 2048;		heap->pools[7].first = NULL;
	heap->pools[8].objsize = 4096;		heap->pools[8].first = NULL;
	heap->pools[9].objsize = 8192;		heap->pools[9].first = NULL;
	heap->pools[10].objsize = 16384;	heap->pools[10].first = NULL;
	log_info("heap subsystem initialized.\n");
}