int initSemaphores( INOUT KERNEL_DATA *krnlDataPtr ) { int i, status; assert( isWritePtr( krnlDataPtr, sizeof( KERNEL_DATA ) ) ); static_assert( MUTEX_LAST == 4, "Mutex value" ); /* Set up the reference to the kernel data block */ krnlData = krnlDataPtr; /* Clear the semaphore table */ for( i = 0; i < SEMAPHORE_LAST; i++ ) krnlData->semaphoreInfo[ i ] = SEMAPHORE_INFO_TEMPLATE; /* Initialize any data structures required to make the semaphore table thread-safe */ MUTEX_CREATE( semaphore, status ); ENSURES( cryptStatusOK( status ) ); /* Initialize the mutexes */ MUTEX_CREATE( mutex1, status ); ENSURES( cryptStatusOK( status ) ); MUTEX_CREATE( mutex2, status ); ENSURES( cryptStatusOK( status ) ); MUTEX_CREATE( mutex3, status ); ENSURES( cryptStatusOK( status ) ); return( CRYPT_OK ); }
void USBDevice_InitDevice(LPSKYETEK_DEVICE device) { LPUSB_DEVICE usbDevice; if( device == NULL ) return; device->internal = &USBDeviceImpl; usbDevice = (LPUSB_DEVICE)malloc(sizeof(USB_DEVICE)); memset(usbDevice, 0, sizeof(USB_DEVICE)); usbDevice->sendBufferWritePtr = usbDevice->sendBuffer; usbDevice->endOfSendBuffer = (unsigned int)usbDevice->sendBuffer + (63 * sizeof(unsigned char)); usbDevice->receiveBufferReadPtr = usbDevice->receiveBufferWritePtr = usbDevice->receiveBuffer; usbDevice->endOfReceiveBuffer = (unsigned int)usbDevice->receiveBuffer + (63 * sizeof(unsigned char)); MUTEX_CREATE(&usbDevice->sendBufferMutex); MUTEX_CREATE(&usbDevice->receiveBufferMutex); usbDevice->packetParity = 0; device->user = (void*)usbDevice; }
// General initizlization of the talker and listener library. Must be called prior to using any other TL APIs. EXTERN_DLL_EXPORT bool openavbTLInitialize(U32 maxTL) { AVB_TRACE_ENTRY(AVB_TRACE_TL); LOG_EAVB_CORE_VERSION(); // CORE_TODO : This can be used to AVB stack init functionality once such a thing exists in the reference implementation AVB_TIME_INIT(); gMaxTL = maxTL; { MUTEX_ATTR_HANDLE(mta); MUTEX_ATTR_INIT(mta); MUTEX_ATTR_SET_TYPE(mta, MUTEX_ATTR_TYPE_DEFAULT); MUTEX_ATTR_SET_NAME(mta, "gTLStateMutex"); MUTEX_CREATE_ERR(); MUTEX_CREATE(gTLStateMutex, mta); MUTEX_LOG_ERR("Error creating mutex"); } gTLHandleList = calloc(1, sizeof(tl_handle_t) * gMaxTL); if (gTLHandleList) { AVB_TRACE_EXIT(AVB_TRACE_TL); return TRUE; } else { AVB_TRACE_EXIT(AVB_TRACE_TL); return FALSE; } }
static unsigned int default_timer_func (void) { static struct timeval start_time; static int virgin = 1; MUTEX_DEFINE_STATIC(timer); struct timeval current_time; unsigned int retval; if (virgin) { virgin = 0; gettimeofday (&start_time, NULL); MUTEX_CREATE(timer); } MUTEX_LOCK(timer); gettimeofday (¤t_time, NULL); current_time.tv_sec -= start_time.tv_sec; current_time.tv_usec -= start_time.tv_usec; retval = current_time.tv_sec * 1000 + current_time.tv_usec / 1000; MUTEX_UNLOCK(timer); return retval; }
void SPIDevice_InitDevice(LPSKYETEK_DEVICE device) { LPSPI_INFO info; TCHAR *ptr; if( device == NULL ) return; ptr = device->address; ptr++; ptr++; ptr++; /* skip SPI */ info = (LPSPI_INFO)malloc(sizeof(SPI_INFO)); memset(info,0,sizeof(SPI_INFO)); info->port_number = _ttoi(ptr); if( _tcsstr(device->address,SKYETEK_I2C_DEVICE_TYPE) != NULL ) info->type = AA_FEATURE_I2C; else info->type = AA_FEATURE_SPI; MUTEX_CREATE(&info->lock); device->internal = &SPIDeviceImpl; device->user = (void*)info; }
void dbg_init() { unsigned int i; /* fprintf(stderr, "asd: %i %i\n", DBG_ERR_MASK_LINE, DBG_ERR_SHIFT_LINE); */ //exit(1); if ((dbg_g = malloc(sizeof(struct dbg_global))) == NULL) { exit(EC__EXIT__NO_RECOVER); } memset(dbg_g, 0, sizeof(struct dbg_global)); if (gettimeofday(&(dbg_g->dbg_utime_proc_start), NULL) != 0) { exit(EC__EXIT__NO_RECOVER); } #ifndef PLATFORM_WINDOWS dbg_set_signal_handler(SIGSEGV, dbg_handler_segv); #endif for (i = 0; i < DBG_OUTPUT_LIST_SIZE; ++i) { dbg_g->dbg_fd_out_list[i].fd = 0; dbg_g->dbg_fd_out_list[i].options = 0; } dbg_g->dbg_fds_used = 0; if (MUTEX_CREATE(&(dbg_g->dbg_fd_out_lock)) != 0) { exit(EC__EXIT__NO_RECOVER); } }
int main(int argc, char** argv) { initGTKStuff(&argc, &argv); // this stuff works only on unix yet #ifdef XP_UNIX MUTEX_CREATE(g_mutex); COND_CREATE(g_cond); JVMP_Monitor mon = JVMP_MONITOR_INITIALIZER(g_mutex, g_cond); g_mon = &mon; #endif gtk_main(); return 0; };
int initAllocation( INOUT KERNEL_DATA *krnlDataPtr ) { int status; assert( isWritePtr( krnlDataPtr, sizeof( KERNEL_DATA ) ) ); /* Set up the reference to the kernel data block */ krnlData = krnlDataPtr; /* Clear the list head and tail pointers */ krnlData->allocatedListHead = krnlData->allocatedListTail = NULL; /* Initialize any data structures required to make the allocation thread- safe */ MUTEX_CREATE( allocation, status ); ENSURES( cryptStatusOK( status ) ); return( CRYPT_OK ); }
extern "C" ylog_t *ylog_open(void *caller, ylog_output_level_t level, ylog_output_position_t pos, ylog_output_time_t timer, ylog_output_fold_t fold, ylog_callback_t cb) { if (!cb) return NULL; ylog_t *ylog = (ylog_t *)malloc(sizeof(ylog_t)); ylog->caller = caller; ylog->level = level; ylog->position = (pos != 0); ylog->timer = (timer != 0); ylog->fold = (fold != 0); ylog->cb = cb; ylog->start_millisecond = GetTimeMS(); MUTEX_CREATE(ylog->cb_mutex); ylog->buf = (char *)calloc(1, BUF_LEN); ylog->cache = (char *)calloc(1, BUF_LEN); ylog->repeat_counter = 0; return ylog; }
int main(int argc, char *argv[]) { configureSandbox(); createCrashFile(); registerExtensions(); //Initialisation MUTEX_CREATE(DBRefreshMutex); loadEmailProfile(); initializeDNSCache(); #ifdef VERBOSE_DB_MANAGEMENT removeFolder("log"); mkdirR("log"); #endif atexit(cleanup); createNewThread(networkAndVersionTest, NULL); //On met le test dans un nouveau thread pour pas ralentir le démarrage setupBDDCache(); return launchApp(argc, argv); }
int i2c_init() { volatile AT91PS_TWI pTWI = AT91C_BASE_TWI; pTWI->TWI_CR = AT91C_TWI_SWRST; pTWI->TWI_CR &= ~(AT91C_TWI_SWRST); uint32_t s; s = pTWI->TWI_SR; TRACE_I2C("TWI_SR %x\r\n", s); s = pTWI->TWI_SR; TRACE_I2C("TWI_SR %x\r\n", s); pTWI->TWI_CWGR = 0x048585; //I2C clk cca 9kHz //i2c_mutex = xSemaphoreCreateMutex(); i2c_mutex = MUTEX_CREATE(); if(i2c_mutex == NULL) { panic("i2c_init"); } #if I2C_IRQ vSemaphoreCreateBinary(i2c_semaphore); xSemaphoreTake(i2c_semaphore, -1); // Initialize the interrupts pTWI->TWI_IDR = 0xffffffff; unsigned int mask = 0x1 << AT91C_ID_TWI; // Disable the interrupt controller & register our interrupt handler AT91C_BASE_AIC->AIC_IDCR = mask ; AT91C_BASE_AIC->AIC_SVR[ AT91C_ID_TWI ] = (unsigned int)i2c_Isr_Wrapper; AT91C_BASE_AIC->AIC_SMR[ AT91C_ID_TWI ] = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL | IRQ_I2C_PRI; AT91C_BASE_AIC->AIC_ICCR = mask; AT91C_BASE_AIC->AIC_IECR = mask; #endif return 0; }
bool openavbAcmpSMControllerStart() { AVB_TRACE_ENTRY(AVB_TRACE_ACMP); openavbAcmpSMControllerVars.inflight = openavbListNewList(); if (!openavbAcmpSMControllerVars.inflight) { AVB_LOG_ERROR("Unable to create inflight list. ACMP protocol not started."); AVB_TRACE_EXIT(AVB_TRACE_ACMP); return FALSE; } MUTEX_ATTR_HANDLE(mta); MUTEX_ATTR_INIT(mta); MUTEX_ATTR_SET_TYPE(mta, MUTEX_ATTR_TYPE_DEFAULT); MUTEX_ATTR_SET_NAME(mta, "openavbAcmpSMControllerMutex"); MUTEX_CREATE_ERR(); MUTEX_CREATE(openavbAcmpSMControllerMutex, mta); MUTEX_LOG_ERR("Could not create/initialize 'openavbAcmpSMControllerMutex' mutex"); SEM_ERR_T(err); SEM_INIT(openavbAcmpSMControllerSemaphore, 1, err); SEM_LOG_ERR(err); // Start the State Machine bool errResult; bRunning = TRUE; THREAD_CREATE(openavbAcmpSmControllerThread, openavbAcmpSmControllerThread, NULL, openavbAcmpSMControllerThreadFn, NULL); THREAD_CHECK_ERROR(openavbAcmpSmControllerThread, "Thread / task creation failed", errResult); if (errResult) { bRunning = FALSE; AVB_TRACE_EXIT(AVB_TRACE_ACMP); return FALSE; } AVB_TRACE_EXIT(AVB_TRACE_ACMP); return TRUE; }
/* __libnet_internal__conns_init: (internal) * Performs internal initialisation. */ void __libnet_internal__conns_init() { __libnet_internal__openconns = (struct __conn_list_t *) malloc (sizeof (struct __conn_list_t)); __libnet_internal__openconns->next = NULL; __libnet_internal__openconns->conn = NULL; MUTEX_CREATE(__libnet_internal__openconns); }
// Called from openavbTLThreadFn() which is started from openavbTLRun() void openavbTLRunListener(tl_state_t *pTLState) { AVB_TRACE_ENTRY(AVB_TRACE_TL); if (!pTLState) { AVB_LOG_ERROR("Invalid TLState"); AVB_TRACE_EXIT(AVB_TRACE_TL); return; } openavb_tl_cfg_t *pCfg = &pTLState->cfg; pTLState->pPvtListenerData = calloc(1, sizeof(listener_data_t)); if (!pTLState->pPvtListenerData) { AVB_LOG_WARNING("Failed to allocate listener data."); return; } AVBStreamID_t streamID; memset(&streamID, 0, sizeof(streamID)); memcpy(streamID.addr, pCfg->stream_addr.mac, ETH_ALEN); streamID.uniqueID = pCfg->stream_uid; AVB_LOGF_INFO("Attach "STREAMID_FORMAT, STREAMID_ARGS(&streamID)); // Create Stats Mutex { MUTEX_ATTR_HANDLE(mta); MUTEX_ATTR_INIT(mta); MUTEX_ATTR_SET_TYPE(mta, MUTEX_ATTR_TYPE_DEFAULT); MUTEX_ATTR_SET_NAME(mta, "TLStatsMutex"); MUTEX_CREATE_ERR(); MUTEX_CREATE(pTLState->statsMutex, mta); MUTEX_LOG_ERR("Could not create/initialize 'TLStatsMutex' mutex"); } // Tell endpoint to listen for our stream. // If there is a talker, we'll get callback (above.) pTLState->bConnected = openavbTLRunListenerInit(pTLState->endpointHandle, &streamID); if (pTLState->bConnected) { bool bServiceIPC; // Notify AVDECC Msg of the state change. openavbAvdeccMsgClntNotifyCurrentState(pTLState); // Do until we are stopped or lose connection to endpoint while (pTLState->bRunning && pTLState->bConnected) { // Listen for an RX frame (or just sleep if not streaming) bServiceIPC = listenerDoStream(pTLState); if (bServiceIPC) { // Look for messages from endpoint. Don't block (timeout=0) if (!openavbEptClntService(pTLState->endpointHandle, 0)) { AVB_LOGF_WARNING("Lost connection to endpoint "STREAMID_FORMAT, STREAMID_ARGS(&streamID)); pTLState->bConnected = FALSE; pTLState->endpointHandle = 0; } } } // Stop streaming listenerStopStream(pTLState); { MUTEX_CREATE_ERR(); MUTEX_DESTROY(pTLState->statsMutex); // Destroy Stats Mutex MUTEX_LOG_ERR("Error destroying mutex"); } // withdraw our listener attach if (pTLState->bConnected) openavbEptClntStopStream(pTLState->endpointHandle, &streamID); // Notify AVDECC Msg of the state change. openavbAvdeccMsgClntNotifyCurrentState(pTLState); } else { AVB_LOGF_WARNING("Failed to connect to endpoint "STREAMID_FORMAT, STREAMID_ARGS(&streamID)); } if (pTLState->pPvtListenerData) { free(pTLState->pPvtListenerData); pTLState->pPvtListenerData = NULL; } AVB_TRACE_EXIT(AVB_TRACE_TL); }
/* init: * Initialises the driver. Return zero if successful, non-zero if not. */ static int local_init(void) { port_list = NULL; MUTEX_CREATE(port_list); return 0; }
void initializeTags(void * mainCache) { MUTEX_CREATE(concurentColdUpdate); sqlite3 * coldDB = NULL; //Create the tables in the main cache createTagsTable(mainCache); if((!checkFileExist(TAG_DB) || sqlite3_open(TAG_DB , &coldDB) != SQLITE_OK) && (!checkFileExist(WIP_TAG_DB) || sqlite3_open(WIP_TAG_DB, &coldDB) != SQLITE_OK)) { //Error, we should reset it with the version we ship with then trigger an update resetTagsToLocal(); if(!checkFileExist(TAG_DB) || sqlite3_open(TAG_DB , &coldDB) != SQLITE_OK) { alertExit("We have significant issues setting up our environment, this may be caused by permission issues, please contact us at [email protected]"); } } sqlite3_stmt * requestRead, *requestWrite; //Build the tag base if((requestRead = createRequest(coldDB, "SELECT "DBNAMETOID(RDB_tagID)", "DBNAMETOID(RDB_tagName)" FROM "TABLE_TAGS)) != NULL) { requestWrite = tagUpdateQuery(mainCache, false); if(requestWrite != NULL) { while(sqlite3_step(requestRead) == SQLITE_ROW) { sqlite3_bind_int(requestWrite, 1, sqlite3_column_int(requestRead, 0)); sqlite3_bind_text(requestWrite, 2, (void *) sqlite3_column_text(requestRead, 1), -1, SQLITE_STATIC); if(sqlite3_step(requestWrite) != SQLITE_DONE) { #ifdef EXTENSIVE_LOGGING uint ID = (uint32_t) sqlite3_column_int(requestRead, 0); const unsigned char * text = sqlite3_column_text(requestRead, 1); if(text == NULL) logR("Error building the tag DB for ID %d: no text!", ID); else logR("Error building the tag DB for ID %d of text %s!", ID, text); #endif } sqlite3_reset(requestWrite); } destroyRequest(requestWrite); } destroyRequest(requestRead); } //Build the category base if((requestRead = createRequest(coldDB, "SELECT "DBNAMETOID(RDB_CAT_ID)", "DBNAMETOID(RDB_CAT_rootID)", "DBNAMETOID(RDB_CAT_name)" FROM "TABLE_CATEGORY)) != NULL) { requestWrite = catUpdateQuery(mainCache, false); if(requestWrite != NULL) { while(sqlite3_step(requestRead) == SQLITE_ROW) { sqlite3_bind_int(requestWrite, 1, sqlite3_column_int(requestRead, 0)); sqlite3_bind_int(requestWrite, 2, sqlite3_column_int(requestRead, 1)); sqlite3_bind_text(requestWrite, 3, (void *) sqlite3_column_text(requestRead, 2), -1, SQLITE_STATIC); for(byte i = 0; i < 32; i++) { sqlite3_bind_int(requestWrite, i + 4, sqlite3_column_int(requestRead, i + 3)); } if(sqlite3_step(requestWrite) != SQLITE_DONE) { #ifdef EXTENSIVE_LOGGING uint ID = (uint32_t) sqlite3_column_int(requestRead, 0); const unsigned char * text = sqlite3_column_text(requestRead, 2); if(text == NULL) logR("Error building the category DB for ID %d: no text!", ID); else logR("Error building the category DB for ID %d of text %s!", ID, text); #endif } sqlite3_reset(requestWrite); } destroyRequest(requestWrite); } destroyRequest(requestRead); } sqlite3_close(coldDB); }
/** * Creates a new socket and connects to server if it is a client, * or does the binding and starts listening on a port if it is server. * Returns a reference to the newly created connection. * * @param side 0 if it is a client, 1 if it is a server * @param addr address to connect for clients or to listen on * for server, if NULL for server listens on INADDR_ANY * @param port port to connect or to listen on * @param max_connections max number of connections that the server can * accept. does not apply for clients. * @param nonblocking TRUE if nonblocking is desired, otherwise FALSE * * @return pointer to the newly created socket, on error * returns NULL */ SOCKET_T* socket_create(int side, char* addr, int port, int max_connections, int nonblocking) { SOCKET_T* new_socket = NULL; struct sockaddr_in service; char buffer[_BUFFER_SIZE_S]; int res; int socket_handle; // Validates paramter if (side < 0 || side > 1) { sprintf(buffer, "socket_create fail: parametros no validos"); return NULL; } // Configurates the service service.sin_family = AF_INET; service.sin_port = htons((unsigned short)port); if (addr == NULL) { service.sin_addr.s_addr = htonl(INADDR_ANY); } else { service.sin_addr.s_addr = inet_addr(addr); } // // Creates socket and does the binding and listening // operations for server or connect for clients // // Creates socket if (nonblocking == TRUE) { socket_handle = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0); } else { socket_handle = socket(AF_INET, SOCK_STREAM, 0); } if (socket_handle == -1) { sprintf(buffer, "socket failed with error: %d\n", errno); LOGGER(__FUNCTION__, buffer); return NULL; } // If it is server if (side == 1) { // Binds the socket to the port res = bind (socket_handle, (struct sockaddr *) &service, sizeof (service)); if (res == -1) { sprintf(buffer, "socket failed with error: %d\n", errno); LOGGER(__FUNCTION__, buffer); shutdown(socket_handle, SHUT_RDWR); return NULL; } // Starts listening on the port res = listen(socket_handle, max_connections); if (res == -1) { sprintf(buffer, "listen fallo con el error: %d\n", errno); LOGGER(__FUNCTION__, buffer); shutdown(socket_handle, SHUT_RDWR); return NULL; } } // If it is client else { // Connects to the server res = connect(socket_handle, (struct sockaddr *) &service, sizeof (service)); if ( res == -1) { // Unless connection is in progress if ( errno != EINPROGRESS ) { sprintf(buffer, "connect failed with error: %d\n", errno); LOGGER(__FUNCTION__, buffer); shutdown(socket_handle, SHUT_RDWR); return NULL; } } } // Configures timeouts for read/write { struct timeval timeout; timeout.tv_sec = RW_TIMEOUT; timeout.tv_usec = 0; res = setsockopt(socket_handle, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)); if (res == -1) { sprintf(buffer, "setsockopt failed with error: %d\n", errno); LOGGER(__FUNCTION__, buffer); } res = setsockopt(socket_handle, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)); if (res == -1) { sprintf(buffer, "setsockopt failed with error: %d\n", errno); LOGGER(__FUNCTION__, buffer); } } // Allocates space for the socket structure new_socket = malloc(sizeof( SOCKET_T )); memset(new_socket, 0x00, sizeof( SOCKET_T )); // Creates mutex for thread-safe socket new_socket->mutex = (MUTEX_T*)malloc(sizeof(struct _mutex_t) ); memset(new_socket->mutex, 0x00, sizeof(struct _mutex_t)); MUTEX_CREATE(&new_socket->mutex); // Copies handle to the socket structure new_socket->handle = socket_handle; return new_socket; }
/** * Accepts a connection and returns a socket * for the recently accepted connection * * @param listen_socket socket in a 'listening' state * @param accept_socket pointer by reference to store the accepted connection socket * * @return TRUE if connection was accepted, otherwise FALSE */ int socket_accept(SOCKET_T * listen_socket, SOCKET_T ** accept_socket) { int socket_handle; SOCKET_T* new_acc_socket; struct sockaddr sa_client; unsigned int sa_client_size = sizeof(sa_client); char buffer[1024]; MUTEX_LOCK(listen_socket->mutex); if ( listen_socket != NULL ) { // Allocates space for the socket structure new_acc_socket = malloc(sizeof( SOCKET_T )); memset(new_acc_socket, 0x00, sizeof( SOCKET_T )); // Accepts connection socket_handle = accept(listen_socket->handle, (struct sockaddr *) &sa_client, &sa_client_size); if (socket_handle == -1) { if ( errno == EAGAIN || errno == EWOULDBLOCK ) { // Returns invalid, no connections pending free(new_acc_socket); MUTEX_UNLOCK(listen_socket->mutex); return FALSE; } else { sprintf(buffer, "accept failed with error: %d\n", errno); LOGGER(__FUNCTION__, buffer); free(new_acc_socket); MUTEX_UNLOCK(listen_socket->mutex); return FALSE; } } else { // Stores the new socket handle in the structure new_acc_socket->handle = socket_handle; // Copies the structure to the output parameter *accept_socket = new_acc_socket; // Creates mutex for the new socket (*accept_socket)->mutex = (MUTEX_T*)malloc(sizeof(struct _mutex_t) ); memset( (*accept_socket)->mutex, 0x00, sizeof(struct _mutex_t)); MUTEX_CREATE( &((*accept_socket)->mutex) ); MUTEX_UNLOCK(listen_socket->mutex); return TRUE; } } MUTEX_UNLOCK(listen_socket->mutex); return FALSE; }
// Called from openavbTLThreadFn() which is started from openavbTLRun() void openavbTLRunTalker(tl_state_t *pTLState) { AVB_TRACE_ENTRY(AVB_TRACE_TL); if (!pTLState) { AVB_LOG_ERROR("Invalid TLState"); AVB_TRACE_EXIT(AVB_TRACE_TL); return; } pTLState->pPvtTalkerData = calloc(1, sizeof(talker_data_t)); if (!pTLState->pPvtTalkerData) { AVB_LOG_WARNING("Failed to allocate talker data."); return; } // Create Stats Mutex { MUTEX_ATTR_HANDLE(mta); MUTEX_ATTR_INIT(mta); MUTEX_ATTR_SET_TYPE(mta, MUTEX_ATTR_TYPE_DEFAULT); MUTEX_ATTR_SET_NAME(mta, "TLStatsMutex"); MUTEX_CREATE_ERR(); MUTEX_CREATE(pTLState->statsMutex, mta); MUTEX_LOG_ERR("Could not create/initialize 'TLStatsMutex' mutex"); } /* If using endpoint register talker, else register with tpsec */ pTLState->bConnected = openavbTLRunTalkerInit(pTLState); if (pTLState->bConnected) { bool bServiceIPC; // Do until we are stopped or loose connection to endpoint while (pTLState->bRunning && pTLState->bConnected) { // Talk (or just sleep if not streaming.) bServiceIPC = talkerDoStream(pTLState); // TalkerDoStream() returns TRUE once per second, // so that we can service our IPC at that low rate. if (bServiceIPC) { // Look for messages from endpoint. Don't block (timeout=0) if (!openavbEptClntService(pTLState->endpointHandle, 0)) { AVB_LOGF_WARNING("Lost connection to endpoint, will retry "STREAMID_FORMAT, STREAMID_ARGS(&(((talker_data_t *)pTLState->pPvtTalkerData)->streamID))); pTLState->bConnected = FALSE; pTLState->endpointHandle = 0; } } } // Stop streaming talkerStopStream(pTLState); { MUTEX_CREATE_ERR(); MUTEX_DESTROY(pTLState->statsMutex); // Destroy Stats Mutex MUTEX_LOG_ERR("Error destroying mutex"); } // withdraw our talker registration if (pTLState->bConnected) openavbEptClntStopStream(pTLState->endpointHandle, &(((talker_data_t *)pTLState->pPvtTalkerData)->streamID)); openavbTLRunTalkerFinish(pTLState); } else { AVB_LOGF_WARNING("Failed to connect to endpoint"STREAMID_FORMAT, STREAMID_ARGS(&(((talker_data_t *)pTLState->pPvtTalkerData)->streamID))); } if (pTLState->pPvtTalkerData) { free(pTLState->pPvtTalkerData); pTLState->pPvtTalkerData = NULL; } AVB_TRACE_EXIT(AVB_TRACE_TL); }
Threading() { THREAD_INIT(); MUTEX_CREATE(); }
/** * Make sure the DB is current and then go into FAM-monitored mode * updating the DB all the time in the background. Exits after a * signal (i.e. SIGHUP/SIGINT) is received. */ static int build(const char * libraries, const char * dbName, size_t mem_limit, const char * log, int argc, char * argv[]) { int i; unsigned int ret; DIC cls; char * ename; FILE * logfile; PTHREAD_T workerThread; void * unused; cls.argc = argc; cls.argv = argv; cls.deferredCount = 0; cls.deferredTruncations = NULL; logfile = NULL; if (log != NULL) { logfile = fopen(log, "w+"); if (logfile == NULL) my_log(stderr, DOODLE_LOG_CRITICAL, _("Could not open '%s' for logging: %s.\n"), log, strerror(errno)); } cls.logContext = logfile; cls.log = &my_log; if (dbName == NULL) { my_log(logfile, DOODLE_LOG_CRITICAL, _("No database specified. Aborting.\n")); return -1; } for (i=strlen(dbName);i>=0;i--) { if (dbName[i] == ':') { my_log(logfile, DOODLE_LOG_CRITICAL, _("'%s' is an invalid database filename (has a colon) for building database (option '%s').\n"), dbName, "-b"); return -1; } } ename = expandFileName(dbName); if (ename == NULL) return -1; cls.ename = ename; cls.tree = DOODLE_tree_create(&my_log, logfile, ename); cls.treePresent = 1; if (cls.tree == NULL) return -1; if (mem_limit != 0) DOODLE_tree_set_memory_limit(cls.tree, mem_limit); cls.elist = forkExtractor(do_default, libraries, &my_log, logfile); if (cls.elist == NULL) { DOODLE_tree_destroy(cls.tree); return -1; } if (0 != FAMOpen2(&cls.fc, "doodled")) { my_log(logfile, DOODLE_LOG_CRITICAL, _("Failed to connect to fam. Aborting.\n")); DOODLE_tree_destroy(cls.tree); return -1; } cls.fr = NULL; cls.frPos = 0; cls.frSize = 0; GROW(cls.fr, cls.frSize, 128); cls.frNames = NULL; ret = 0; GROW(cls.frNames, ret, 128); ret = 0; MUTEX_CREATE(&cls.lock); if (0 != PTHREAD_CREATE(&workerThread, &worker, &cls, 64 * 1024)) { my_log(logfile, DOODLE_LOG_CRITICAL, _("Failed to create worker thread: %s"), strerror(errno)); ret = -1; } else { wait_for_shutdown(); cls.continueRunning = 0; SEMAPHORE_UP(cls.signal); PTHREAD_JOIN(&workerThread, &unused); } MUTEX_DESTROY(&cls.lock); my_log(logfile, DOODLE_LOG_VERBOSE, _("doodled is shutting down.\n")); if (cls.frPos == 0) { my_log(logfile, DOODLE_LOG_CRITICAL, _("No files exist that doodled would monitor for changes. Exiting.\n")); } for (i=0;i<cls.frSize;i++) { if (cls.frNames[i] != NULL) { my_log(logfile, DOODLE_LOG_VERBOSE, _("Cancelling fam monitor '%s'.\n"), cls.frNames[i]); free(cls.frNames[i]); } } for (i=cls.deferredCount-1;i>=0;i--) free(cls.deferredTruncations[i]); GROW(cls.deferredTruncations, cls.deferredCount, 0); i = cls.frSize; GROW(cls.fr, cls.frSize, 0); cls.frSize = i; GROW(cls.frNames, cls.frSize, 0); my_log(logfile, DOODLE_LOG_VERBOSE, _("Unloading libextractor plugins.\n")); joinExtractor(cls.elist); free(ename); if (logfile != NULL) fclose(logfile); return ret; }
sqlite3* getPtrRecentDB() { sqlite3 * internalDB = NULL; bool initialCheckRequired = !recentMutexInitialized; if(!recentMutexInitialized) { MUTEX_CREATE(recentMutex); recentMutexInitialized = true; } MUTEX_LOCK(recentMutex); if(sqlite3_open("recent.db", &internalDB) != SQLITE_OK) { logR("Couldn't open the recent database, abort :("); internalDB = NULL; } else if(initialCheckRequired) { uint retValue = checkRecentDBValid(internalDB); if(retValue != RECENT_CHECK_RETVAL_OK) { if(retValue & RECENT_CHECK_RETVAL_INVALID_PROJ) { //On la détruit, et on recrée sqlite3_stmt * request = createRequest(internalDB, "DROP TABLE IF EXISTS `"PROJECT_TABLE"`"); sqlite3_step(request); destroyRequest(request); request = createRequest(internalDB, "CREATE TABLE "PROJECT_TABLE" ("DBNAMETOID(RDB_REC_lastRead)" INTEGER, "DBNAMETOID(RDB_REC_lastDL)" INTEGER, "DBNAMETOID(RDB_REC_repo)" INTEGER, "DBNAMETOID(RDB_REC_projectID)" INTEGER, "DBNAMETOID(RDB_isLocal)" INTEGER);"); if(request == NULL || sqlite3_step(request) != SQLITE_DONE) { destroyRequest(request); sqlite3_close(internalDB); internalDB = NULL; } else destroyRequest(request); } if(internalDB != NULL && retValue & RECENT_CHECK_RETVAL_INVALID_STATE) { //On la détruit, et on recrée sqlite3_stmt * request = createRequest(internalDB, "DROP TABLE IF EXISTS `"STATE_TABLE"`"); sqlite3_step(request); destroyRequest(request); request = createRequest(internalDB, "CREATE TABLE "STATE_TABLE" ("DBNAMETOID(RDB_REC_repo)" INTEGER, "DBNAMETOID(RDB_REC_projectID)" INTEGER, "DBNAMETOID(RDB_isLocal)" INTEGER, "DBNAMETOID(RDB_REC_lastIsTome)" INTEGER, "DBNAMETOID(RDB_REC_lastCTID)" INTEGER, "DBNAMETOID(RDB_REC_lastPage)" INTEGER, "DBNAMETOID(RDB_REC_wasLastPageOfCT)" INTEGER, "DBNAMETOID(RDB_REC_lastZoom)" FLOAT, "DBNAMETOID(RDB_REC_lastScrollerX)" FLOAT, "DBNAMETOID(RDB_REC_lastScrollerY)" FLOAT, "DBNAMETOID(RDB_REC_lastChange)" INTEGER, PRIMARY KEY("DBNAMETOID(RDB_REC_repo)", "DBNAMETOID(RDB_REC_projectID)", "DBNAMETOID(RDB_isLocal)", "DBNAMETOID(RDB_REC_lastIsTome)")) WITHOUT ROWID;"); if(request == NULL || sqlite3_step(request) != SQLITE_DONE) { destroyRequest(request); sqlite3_close(internalDB); internalDB = NULL; } else destroyRequest(request); } } } if(internalDB == NULL) MUTEX_UNLOCK(recentMutex); return internalDB; }