QueueClass *queueInit(QueueClass *queue, int elementSize, int elementMaxCount) { mutexInit(&queue->writeMutex); mutexInit(&queue->readMutex); eventSourceInit(&queue->writeEventSource); eventSourceInit(&queue->readEventSource); queue->elementSize = elementSize; queue->elementMaxCount = 0; queue->buffer = NULL; queueResize(queue, elementMaxCount); return queue; }
/** * userdataMutex() \n * Function which save the mutex \n * @param CHANGE switching \n * newMutex for create a new mutex \n * freeMutex for delete the mutex \n * getMutex to return a pointer to the Mutex \n * @return NULL on error or a pointer to Mutex \n */ void* userdataMutex(CHANGE switching) { static MUTEX userMutex; // Create a new Mutex if(switching == newMutex) { if (mutexInit( &userMutex, "userMutex") == false) { syslogWriteDebug(lerror,"Error: Can't create mutex"); } } // Free the mutex if(switching == freeMutex) { if (mutexFree(&userMutex) == false); syslogWriteDebug(lerror,"Error: Can't free mutex"); return NULL; } // Return mutex if(switching == getMutex) { return (void *) &userMutex; } // No correct parameter syslogFormatWriteDebug(lerror,"Error: False parameter %i",switching); }
void retro_main_log_file_init(const char *path, bool append) { if (log_file_initialized) return; #ifdef NXLINK if (path == NULL && nxlink_connected) mutexInit(&nxlink_mtx); #endif log_file_fp = stderr; if (path == NULL) return; log_file_fp = (FILE*)fopen_utf8(path, append ? "ab" : "wb"); if (!log_file_fp) { log_file_fp = stderr; RARCH_ERR("Failed to open system event log file: %s\n", path); return; } log_file_initialized = true; #if !defined(PS2) /* TODO: PS2 IMPROVEMENT */ /* TODO: this is only useful for a few platforms, find which and add ifdef */ log_file_buf = calloc(1, 0x4000); setvbuf(log_file_fp, (char*)log_file_buf, _IOFBF, 0x4000); #endif }
static void sigMonitorInit() { userSigMon.owner = 0; userSigMon.count = 0; mutexInit(&userSigMon.mutex); condvarInit(&userSigMon.condvar); }
EventLoop::EventLoop() :m_max_fds(NetSettings::epollSize), m_status(STATUS_CLOSED), m_epl(EF_INVALID_SOCKET), m_ctlfd(EF_INVALID_SOCKET), m_ctlfd1(EF_INVALID_SOCKET), m_ops_flag(0), m_id(-1), m_obj(NULL),m_init(NULL), m_clean(NULL) { mutexInit(&m_opcs); }
/** * Intializes all XINU data structures and devices. * @return OK if everything is initialized successfully */ local sysinit(void) { int i = 0; pcb *ppcb = NULL; /* process control block pointer */ semblk *psem = NULL; /* semaphore block pointer */ memblk *pmem = NULL; /* memory block pointer */ /* Initialize system variables */ /* Count this NULLPROC as the first process in the system. */ numproc = 1; /* Initialize free memory list */ freelist.next = pmem = (memblk *) roundmb(minheap); freelist.length = (ulong)truncew((ulong)platform.maxaddr - (ulong)minheap); pmem->next = NULL; pmem->length = freelist.length; /* Initialize process table */ for (i = 0; i < NPROC; i++) { proctab[i].state = PRFREE; } /* initialize null process entry */ ppcb = &proctab[NULLPROC]; ppcb->state = PRCURR; strncpy(ppcb->name, "prnull", 7); ppcb->stkbase = (void *)&end; ppcb->stkptr = NULL; ppcb->stklen = (ulong)minheap - (ulong)&end; ppcb->priority = 0; currpid = NULLPROC; /* Initialize semaphores */ for (i = 0; i < NSEM; i++) { psem = &semtab[i]; psem->state = SFREE; psem->count = 0; psem->queue = newqueue(); } /* initialize bounded-waiting mutex subsystems */ mutexInit(); /* initialize process ready list */ readylist = newqueue(); #if RTCLOCK /* initialize real time clock */ clockinit(); #endif return OK; }
static void init() { mutexInit(); if (centralInitiated) { // reclaim resources from other thread reclaimResources(); } else { centralArenaInit(); } // handling fork issues // initialize pthread_atfork pthread_atfork(&prepare, &parent, &child); }
void initAprilTag() { int i; for (i = 0; i < MAX_APRILTAG; i++) { aprilTagData[i].id = i; aprilTagData[i].up = 0; aprilTagData[i].bcastTime = 0; aprilTagData[i].rid = -1; aprilTagData[i].display = 0; aprilTagData[i].head = 0; aprilTagData[i].active = 0; mutexInit(&aprilTagData[i].mutex); } }
int sysMonitorInit(sys_mon_t *mid) { int ret; sysAssert(mid != SYS_MID_NULL); ret = mutexInit(&mid->mutex); ret = (ret == SYS_OK ? condvarInit(&mid->cv_monitor) : ret); mid->entry_count = 0; mid->monitor_owner = SYS_THREAD_NULL; mid->contention_count = 0; INIT_MONITOR_WAIT_QUEUE( mid->mwait_queue ); return ret; }
/* * Initialize global data structure for non-blocking * close semantics for Solaris 2.6 and ealier. */ int InitializeIO(rlim_t limit) { int i; fd_limit = (int) limit; fd_table = (file_t *) sysCalloc(fd_limit, sizeof(file_t)); if (fd_table == 0) { return SYS_ERR; } for (i = 0; i < fd_limit; i++) { mutexInit(&(fd_table[i].lock)); } return SYS_OK; }
void retro_main_log_file_init(const char *path) { if (log_file_initialized) return; #ifdef NXLINK if (path == NULL && nxlink_connected) mutexInit(&nxlink_mtx); #endif log_file_fp = stderr; if (path == NULL) return; log_file_fp = (FILE*)fopen_utf8(path, "wb"); log_file_initialized = true; /* TODO: this is only useful for a few platforms, find which and add ifdef */ log_file_buf = calloc(1, 0x4000); setvbuf(log_file_fp, (char*)log_file_buf, _IOFBF, 0x4000); }
//------------------------------------------------------------------------------ ThreadSwarm::ThreadSwarm(Shell &parent) : ShellCommand(parent) { result res; res = mutexInit(&queueLock); if (res == E_OK) res = semInit(&queueSynchronizer, THREAD_COUNT); if (res != E_OK) { owner.log("swarm: initialization error"); exit(EXIT_FAILURE); } for (unsigned int i = 0; i < THREAD_COUNT; ++i) { WorkerThread *thread = new WorkerThread(*this); thread->start(); pool.push(thread); } }
Logger::Logger(const string defaultFile) : logLevel(4), threaded(1), canlog(0), numChannels(0), numLogfiles(0) { /* Logger is set to not threaded from QualityManager.cpp via setThreaded(0) if and only if not a single quality component is configured as threaded */ unlink(defaultFile.c_str()); // setDefaultLogfile(defaultFile); #ifdef ENABLE_THREADS if (threaded) { mutexInit(&maccess); } #endif channels.resize(INITIAL_NB_CHANNELS); logfiles.resize(INITIAL_NB_LOGFILES); logfile = defaultFile; ch = createChannel("Logger"); canlog = 1; }
void initializeContentionCountMutex() { mutexInit(&contention_count_mutex); }
/** * Initializes ressources of the client thread * @return - none */ void ressourcesInit() { mutexInit(&clientMutex, "ClientMutex"); clientStage = PLAYER_STAGE_PREPARATION; clientSocket = -1; }
void ataInit(AHCIController *ctrl, int portno) { ATADevice *dev = NEW(ATADevice); ctrl->ataDevices[ctrl->numAtaDevices++] = dev; mutexInit(&dev->lock); dev->ctrl = ctrl; dev->port = &ctrl->regs->ports[portno]; dev->sd = NULL; // stop the command engine while setting up the commands and stuff ahciStopCmd(dev->port); // create the operations area if (dmaCreateBuffer(&dev->dmabuf, sizeof(AHCIOpArea), 0) != 0) { // it didn't work kprintf("sdahci: failed to allocate operations area\n"); kfree(dev); ctrl->numAtaDevices--; return; }; // set up the operations area AHCIOpArea *opArea = (AHCIOpArea*) dmaGetPtr(&dev->dmabuf); memset(opArea, 0, sizeof(AHCIOpArea)); // set the command list and FIS area dev->port->clb = dmaGetPhys(&dev->dmabuf) + __builtin_offsetof(AHCIOpArea, cmdlist); dev->port->fb = dmaGetPhys(&dev->dmabuf) + __builtin_offsetof(AHCIOpArea, fisArea); // we only use the first command header, so initialize it to point to the table opArea->cmdlist[0].ctba = dmaGetPhys(&dev->dmabuf) + __builtin_offsetof(AHCIOpArea, cmdtab); // start the command engine ahciStartCmd(dev->port); dev->port->serr = dev->port->serr; dev->port->is = dev->port->is; // send the IDENTIFY command. opArea->cmdlist[0].cfl = sizeof(FIS_REG_H2D)/4; // FIS length in dwords opArea->cmdlist[0].w = 0; // read data opArea->cmdlist[0].prdtl = 1; // only one PRDT entry opArea->cmdlist[0].p = 1; opArea->cmdtab.prdt[0].dba = dmaGetPhys(&dev->dmabuf) + __builtin_offsetof(AHCIOpArea, id); opArea->cmdtab.prdt[0].dbc = 511; // length-1 opArea->cmdtab.prdt[0].i = 0; // do not interrupt // set up command FIS FIS_REG_H2D *cmdfis = (FIS_REG_H2D*) opArea->cmdtab.cfis; cmdfis->fis_type = FIS_TYPE_REG_H2D; cmdfis->c = 1; cmdfis->command = ATA_CMD_IDENTIFY; // issue the command and await completion __sync_synchronize(); if (ahciIssueCmd(dev->port) != 0) { kprintf("sdahci: error during identification\n"); return; }; uint32_t *cmdsetptr = (uint32_t*) &opArea->id[ATA_IDENT_COMMANDSETS]; uint32_t cmdset = *cmdsetptr; uint64_t size; if (cmdset & (1 << 26)) { uint64_t *szptr = (uint64_t*) &opArea->id[ATA_IDENT_MAX_LBA_EXT]; size = (*szptr) & 0xFFFFFFFFFFFF; } else { uint32_t *szptr = (uint32_t*) &opArea->id[ATA_IDENT_MAX_LBA]; size = (uint64_t) (*szptr); }; char model[41]; int k; for (k=0; k<40; k+=2) { model[k] = opArea->id[ATA_IDENT_MODEL + k + 1]; model[k+1] = opArea->id[ATA_IDENT_MODEL + k]; }; model[40] = 0; char *check = &model[39]; while (*check == ' ') { if (check == model) break; *check-- = 0; }; kprintf("sdahci: size in MB: %lu, model: %s\n", size / 1024 / 2, model); SDParams sdpars; sdpars.flags = 0; sdpars.blockSize = 512; sdpars.totalSize = size * 512; // do a cache flush opArea->cmdlist[0].w = 0; opArea->cmdlist[0].p = 0; opArea->cmdlist[0].c = 0; opArea->cmdlist[0].prdtl = 0; cmdfis->fis_type = FIS_TYPE_REG_H2D; cmdfis->c = 1; cmdfis->command = ATA_CMD_CACHE_FLUSH_EXT; cmdfis->lba0 = 0; cmdfis->lba1 = 0; cmdfis->lba2 = 0; cmdfis->device = 1<<6; // LBA mode cmdfis->lba3 = 0; cmdfis->lba4 = 0; cmdfis->lba5 = 0; cmdfis->countl = 0; cmdfis->counth = 0; // issue the flush command int status = ahciIssueCmd(dev->port); kprintf("sdahci: cache flush status: %d\n", status); dev->sd = sdCreate(&sdpars, model, &ataOps, dev); if (dev->sd == NULL) { kprintf("sdahci: SD creation failed\n"); // NOTE: do not free anything; this is done upon removing the driver }; };
/* * Initialize signal handlers for suspend and resume}. */ int np_initialize() { struct sigaction act; char *s; int err; /* Signal numbers used to suspend and resume */ #if __GLIBC__ == 2 && __GLIBC_MINOR__ == 0 #ifdef SIGUNUSED sr_sigsusp = SIGUNUSED; #else sr_sigsusp = SIGLOST; #endif #ifdef SIGPWR sr_sigresu = SIGPWR; #else sr_sigresu = SIGXFSZ; #endif #else /* use real time signals */ /* currently __SIGRTMIN, +1, +2 are all used by LinuxThreads */ sr_sigsusp = SIGRTMIN + 3; sr_sigresu = SIGRTMIN + 4; #endif /* Set up signal handler for suspend and resume */ #if defined(SA_SIGINFO) && !defined(__sparc__) act.sa_handler = 0; act.sa_sigaction = susp_handler; #else act.sa_handler = (__sighandler_t) susp_handler; #endif #ifdef SA_SIGINFO act.sa_flags = SA_RESTART | SA_SIGINFO; #else act.sa_flags = SA_RESTART; #endif sigfillset(&act.sa_mask); if (sigaction(sr_sigsusp, &act, 0) == -1) { return -1; } #if defined(SA_SIGINFO) && !defined(__sparc__) act.sa_handler = 0; act.sa_sigaction = resu_handler; #else act.sa_handler = (__sighandler_t) resu_handler; #endif #ifdef SA_SIGINFO act.sa_flags = SA_SIGINFO; #else act.sa_flags = 0; #endif sigfillset(&act.sa_mask); if (sigaction(sr_sigresu, &act, 0) == -1) { return -1; } /* Initialize semaphore used by np_{suspend/resume} */ if (sem_init(&sr_sem, 0, 0) == -1) { return SYS_ERR; } /* Initialize mutex used by np_{suspend/resume} */ err = mutexInit(&sr_lock); sysAssert(err == 0); return SYS_OK; }
Synchronizer::Synchronizer() { mShared = 0; mutexInit(&mMutex); conditionVarInit(&mCondition); }
static void initSockFnTable() { int (PASCAL FAR* WSAStartupPtr)(WORD, LPWSADATA); WSADATA wsadata; OSVERSIONINFO info; mutexInit(&sockFnTableMutex); mutexLock(&sockFnTableMutex); if (sockfnptrs_initialized == FALSE) { HANDLE hWinsock; /* try to load Winsock2, and if that fails, load Winsock */ hWinsock = LoadLibrary("ws2_32.dll"); if (hWinsock == NULL) { hWinsock = LoadLibrary("wsock32.dll"); winsock2Available = FALSE; } else { winsock2Available = TRUE; } if (hWinsock == NULL) { VM_CALL(jio_fprintf)(stderr, "Could not load Winsock 1 or 2 (error: %d)\n", GetLastError()); } /* If we loaded a DLL, then we might as well initialize it. */ WSAStartupPtr = (int (PASCAL FAR *)(WORD, LPWSADATA)) GetProcAddress(hWinsock, "WSAStartup"); if (WSAStartupPtr(MAKEWORD(1,1), &wsadata) != 0) { VM_CALL(jio_fprintf)(stderr, "Could not initialize Winsock\n"); } sockfnptrs[FN_RECV] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "recv"); sockfnptrs[FN_SEND] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "send"); sockfnptrs[FN_LISTEN] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "listen"); sockfnptrs[FN_BIND] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "bind"); sockfnptrs[FN_ACCEPT] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "accept"); sockfnptrs[FN_RECVFROM] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "recvfrom"); sockfnptrs[FN_SENDTO] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "sendto"); sockfnptrs[FN_SELECT] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "select"); sockfnptrs[FN_CONNECT] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "connect"); sockfnptrs[FN_CLOSESOCKET] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "closesocket"); /* we don't use this */ sockfnptrs[FN_SHUTDOWN] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "shutdown"); sockfnptrs[FN_GETHOSTNAME] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "gethostname"); sockfnptrs[FN_GETHOSTBYADDR] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "gethostbyaddr"); sockfnptrs[FN_GETHOSTBYNAME] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "gethostbyname"); sockfnptrs[FN_HTONS] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "htons"); sockfnptrs[FN_HTONL] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "htonl"); sockfnptrs[FN_NTOHS] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "ntohs"); sockfnptrs[FN_NTOHL] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "ntohl"); sockfnptrs[FN_GETSOCKOPT] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "getsockopt"); sockfnptrs[FN_SETSOCKOPT] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "setsockopt"); sockfnptrs[FN_GETPROTOBYNAME] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "getprotobyname"); sockfnptrs[FN_GETSOCKNAME] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "getsockname"); sockfnptrs[FN_SOCKET] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "socket"); /* in winsock 1, this will simply be 0 */ sockfnptrs[FN_WSASENDDISCONNECT] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "WSASendDisconnect"); sockfnptrs[FN_SOCKETAVAILABLE] = (int (PASCAL FAR *)())GetProcAddress(hWinsock, "ioctlsocket"); } sysAssert(sockfnptrs[FN_RECV] != NULL); sysAssert(sockfnptrs[FN_SEND] != NULL); sysAssert(sockfnptrs[FN_LISTEN] != NULL); sysAssert(sockfnptrs[FN_BIND] != NULL); sysAssert(sockfnptrs[FN_ACCEPT] != NULL); sysAssert(sockfnptrs[FN_RECVFROM] != NULL); sysAssert(sockfnptrs[FN_SENDTO] != NULL); sysAssert(sockfnptrs[FN_SELECT] != NULL); sysAssert(sockfnptrs[FN_CONNECT] != NULL); sysAssert(sockfnptrs[FN_CLOSESOCKET] != NULL); sysAssert(sockfnptrs[FN_SHUTDOWN] != NULL); sysAssert(sockfnptrs[FN_GETHOSTNAME] != NULL); sysAssert(sockfnptrs[FN_GETHOSTBYADDR] != NULL); sysAssert(sockfnptrs[FN_GETHOSTBYNAME] != NULL); sysAssert(sockfnptrs[FN_HTONS] != NULL); sysAssert(sockfnptrs[FN_HTONL] != NULL); sysAssert(sockfnptrs[FN_NTOHS] != NULL); sysAssert(sockfnptrs[FN_NTOHL] != NULL); sysAssert(sockfnptrs[FN_GETSOCKOPT] != NULL); sysAssert(sockfnptrs[FN_SETSOCKOPT] != NULL); sysAssert(sockfnptrs[FN_GETPROTOBYNAME] != NULL); sysAssert(sockfnptrs[FN_GETSOCKNAME] != NULL); sysAssert(sockfnptrs[FN_SOCKET] != NULL); if (winsock2Available) { sysAssert(sockfnptrs[FN_WSASENDDISCONNECT] != NULL); } sysAssert(sockfnptrs[FN_SOCKETAVAILABLE] != NULL); sockfnptrs_initialized = TRUE; mutexUnlock(&sockFnTableMutex); }