void WorkerDelete( Worker *w ) { if( w != NULL ) { if( w->w_Thread ) { DEBUG( "Trying to delete worker!\n" ); if( pthread_mutex_lock( &(w->w_Mut) ) == 0 ) { if( w->w_State == W_STATE_RUNNING || w->w_State == W_STATE_WAITING ) { w->w_Quit = TRUE; DEBUG( "Sending signal!\n" ); pthread_cond_signal( &(w->w_Cond) ); // <- wake up!! pthread_mutex_unlock( &(w->w_Mut) ); DEBUG( "Sending delete directive!\n" ); ThreadDelete( w->w_Thread ); } else pthread_mutex_unlock( &(w->w_Mut) ); } DEBUG( "Worker deleted!\n" ); } // Free up the mutex elements if( w->w_State ) { pthread_cond_destroy( &(w->w_Cond) ); pthread_mutex_destroy( &(w->w_Mut) ); } free( w ); } }
/** * Websocket delete function * * @param ws pointer to WebSocket structure which will be deleted */ void WebSocketDelete( WebSocket* ws ) { if( ws != NULL ) { ws->ws_Quit = TRUE; DEBUG("[WS] Websocket close in progress\n"); int tries = 0; #ifdef ENABLE_WEBSOCKETS_THREADS while( TRUE ) { if( WSThreadNum <= 0 && ws->ws_Thread->t_Launched == FALSE ) { break; } DEBUG("[WS] Closeing WS. Threads: %d\n", WSThreadNum ); sleep( 1 ); tries++; if( tries > 50 ) { //WorkerManagerDebug( SLIB ); tries = 0; } } #endif Log( FLOG_DEBUG, "[WS] Closeing thread\n"); if( ws->ws_Thread ) { ThreadDelete( ws->ws_Thread ); } Log( FLOG_DEBUG, "[WS] Thread closed\n"); if( ws->ws_Context != NULL ) { lws_context_destroy( ws->ws_Context ); ws->ws_Context = NULL; } if( ws->ws_CertPath != NULL ) { } FFree( ws ); } pthread_mutex_destroy( &WSThreadMutex ); }
/** * Destroys a running event manager and the associated list of events * * @param em pointer to the EventManager structure */ void EventManagerDelete( EventManager *em ) { DEBUG("[EventManager] Delete\n"); // remove long time events if( em != NULL ) { em->em_EventThread->t_Quit = TRUE; while( TRUE ) { if( em->em_EventThread->t_Launched == FALSE ) { break; } usleep( 5000 ); } if( em->em_EventThread != NULL ) { DEBUG("[EventManager] Delete thread\n"); ThreadDelete( em->em_EventThread ); } DEBUG("[EventManager] thread removed\n"); // waiting till all functions died while( TRUE ) { if( threadsNo <= 0 ) { break; } DEBUG("[EventManager] Not all threads were closed properly, waiting. ThreadsNo: %d\n", threadsNo ); usleep( 500 ); } CoreEvent *locnce = em->em_EventList; while( locnce != NULL ) { CoreEvent *rem = locnce; locnce = (CoreEvent *)locnce->node.mln_Succ; FFree( rem ); } FFree( em ); } DEBUG("[EventManager] Delete end\n"); }
void SSHServerDelete( SSHServer *ts ) { if( ts != NULL ) { ts->sshs_Quit = TRUE; #ifdef ENABLE_SSH if( ts->sshs_Thread ) { ThreadDelete( ts->sshs_Thread ); } ssh_finalize(); #endif FFree( ts ); } }
void ServiceDelete( Service *s ) { if( s ) { if( s->s_Thread ) { ThreadDelete( s->s_Thread ); } if( s->s_Buffer ) { free( s->s_Buffer ); s->s_Buffer = NULL; } free( s ); } }
/** * Create new worker * * @param nr id of new worker * @return pointer to new Worker structure when success, otherwise NULL */ void WorkerDelete( Worker *w ) { if( w != NULL ) { if( w->w_Thread ) { int count = 0; w->w_Quit = TRUE; while( w->w_State != W_STATE_TO_REMOVE ) { if( pthread_mutex_lock( &(w->w_Mut) ) == 0 ) { pthread_cond_signal( &(w->w_Cond) ); // <- wake up!! pthread_mutex_unlock( &(w->w_Mut) ); } DEBUG("[WorkerThread] State %d quit %d WRKID %d\n", w->w_State, w->w_Quit, w->w_Nr ); if( count++ > 1 ) { usleep( 10000 ); } } ThreadDelete( w->w_Thread ); } // Free up the mutex elements if( w->w_State ) { pthread_cond_destroy( &(w->w_Cond) ); pthread_mutex_destroy( &(w->w_Mut) ); } DEBUG("[WorkerThread] Worker deleted: %d\n", w->w_Nr ); FFree( w ); } }