int uninitPreload (preloadConfig_t *preloadConfig) { int status; int i; int size; // destroy preload thread list size = listSize(PreloadThreadList); for(i=0;i<size;i++) { preloadThreadInfo_t *threadInfo = (preloadThreadInfo_t *)removeFirstElementOfConcurrentList(PreloadThreadList); if(threadInfo->running == PRELOAD_THREAD_RUNNING) { #ifdef USE_BOOST status = threadInfo->thread->join(); #else status = pthread_join(threadInfo->thread, NULL); #endif } if(threadInfo->path != NULL) { free(threadInfo->path); threadInfo->path = NULL; } } if(preloadConfig->clearCache) { // clear all cache _removeAllCaches(); } else { // remove incomplete preload caches _removeAllIncompleteCaches(preloadConfig->cachePath); } FREE_LOCK(PreloadLock); return (0); }
int _freeIFuseConn(iFuseConn_t *tmpIFuseConn) { _ifuseDisconnect(tmpIFuseConn); FREE_STRUCT_LOCK(*tmpIFuseConn); FREE_LOCK(tmpIFuseConn->inuseLock); free (tmpIFuseConn); return 0; }
int uninitLazyUpload (lazyUploadConfig_t *lazyUploadConfig) { // remove incomplete lazy-upload caches _removeAllBufferedFiles(); FREE_LOCK(LazyUploadLock); return (0); }
int uninitPreload (preloadConfig_t *preloadConfig) { if(preloadConfig->clearCache) { // clear all cache _removeAllCaches(); } else { // remove incomplete preload caches _removeAllIncompleteCaches(); } FREE_LOCK(PreloadLock); return (0); }
static void del_agent(t_agent *agent) /* The agent to delete */ /* * Delete the given agent. This is called both by the term_agent routine, * but may also be called by the new_agent routine if something goes * wrong and it needs to bomb out. Therefore we don't assume that all of * the dynamic values have been set */ { del_am_q(agent->ip_am_q); /* Delete the queue */ FREE_LOCK(agent->lck); if(agent->aptr) *agent->aptr = NULL; /* Remove our ref in object */ FREE(agent); } /* del_agent() */
void sc_term(t_sc *sc) /* * Terminate the given controller. */ { static char sc_term = SC_TERM; mq_send(sc->mq, &sc_term, 1, 3); /* Send termination message */ if(pthread_join(sc->thread, NULL)) /* Wait for thread to term */ E("pthread_join() failed"); mq_close(sc->mq); /* Close queue descriptor */ mq_unlink(sc->mq_name); /* Destroy queue itself */ FREE(sc->mq_name); /* Free queue name memory */ FREE_LOCK(sc->lck); /* Destroy the lock */ FREE(sc); /* Last the structure itself */ } /* sc_term() */
void terminate_queue( void ) { FREE_LOCK( qlock ); FREE_SEM( qnotempty ); }
t_sc * sc_init() /* * Create a new syncronisation controller * Returns the ID (address) of the new controller */ { t_sc *sc; /* Structure for controller */ struct mq_attr attr; /* Attributes for queue */ sc = NEW(t_sc); /* Create new structure */ if(!sc) /* Failed ? */ { E("MALLOC() failed"); return NULL; } if(INIT_LOCK(sc->lck)) /* Failed to create lock ? */ { E("Failed to create LOCK"); FREE(sc); return NULL; } /* * Now create the message queue. The name is made up of the * application name and the address of this SC */ sc->mq_name = g_strdup_printf("/" APP_NAME "-%p", sc); /* --- Set up the attributes of the queue --- */ attr.mq_flags = 0; /* NOT nonblock! */ attr.mq_maxmsg = MAX_Q_SIZE; /* Max queued commands */ attr.mq_msgsize = 1; /* Only 1 byte for cmd */ attr.mq_curmsgs = 0; sc->mq = mq_open(sc->mq_name, O_RDWR | O_CREAT, 0600, &attr); if(sc->mq == (mqd_t)-1) { E("Failed to create message queue [%s]", sc->mq_name); FREE_LOCK(sc->lck); FREE(sc->mq_name); FREE(sc); return NULL; } /* * We need to prevent the race condition where sc_wait() gets called * and runs before sc_counter() has been run and grabbed the lock. * So we use the locked flag here to indicate that it 'should' be * locked. So if sc_wait() gets the lock but sees 'locked' is not set * then it immediately relinquishes the lock */ sc->locked = TRUE; sc->waiting = TRUE; /* Waiting for a BEGIN */ sc->delta = 0; /* No messages yet */ if(pthread_create(&sc->thread, NULL, sc_counter, sc)) { E("Failed to create a new thread for sc"); FREE_LOCK(sc->lck); mq_close(sc->mq); /* Close queue descriptor */ mq_unlink(sc->mq_name); /* Destroy queue itself */ FREE(sc->mq_name); FREE(sc); return NULL; } return sc; /* The new controller */ } /* sc_init() */