static int thread_write( UThread* ut, UBuffer* port, const UCell* data ) { UBuffer* buf; ThreadExt* ext = (ThreadExt*) port->ptr.v; ThreadQueue* queue; int type = ur_type(data); if( ur_isSeriesType(type) && ! ur_isShared( data->series.buf ) ) { buf = ur_bufferSerM( data ); if( ! buf ) return UR_THROW; if( ur_isBlockType(type) ) { UCell* it = buf->ptr.cell; UCell* end = it + buf->used; while( it != end ) { type = ur_type(it); if( ur_isWordType(type) ) { if( ur_binding(it) == UR_BIND_THREAD ) ur_unbind(it); } else if( ur_isSeriesType(type) ) { return ur_error( ut, UR_ERR_INTERNAL, "Cannot write block containing series to thread port" ); } ++it; } } } else buf = 0; queue = (port->SIDE == SIDE_A) ? &ext->A : &ext->B; mutexLock( queue->mutex ); if( queue->END_OPEN ) { thread_queue( &queue->buf, data, buf ); condSignal( queue->cond ); writeEvent( queue ); } mutexUnlock( queue->mutex ); return UR_OK; }
DRThread::~DRThread() { if(thread) { //Post Exit to Stream Thread exitCalled = true; if(SDL_SemPost(semaphore)) LOG_WARNING_SDL(); condSignal(); //kill TextureLoad Thread after 1/2 second SDL_Delay(500); // SDL_KillThread(thread); SDL_WaitThread(thread, NULL); //LOG_WARNING_SDL(); thread = NULL; SDL_DestroySemaphore(semaphore); SDL_DestroyMutex(mutex); SDL_DestroyCond(condition); } }
/** \brief Signal the condition and wakeup all thread waiting * for the condition * * \b os_condBroadcast calls \b pthread_cond_broadcast to broadcast * the condition. */ os_result os_condBroadcast ( os_cond *cond) { return condSignal(cond, BROADCAST_BIT_MASK); }
/** \brief Signal the condition and wakeup one thread waiting * for the condition * * \b os_condSignal calls \b pthread_cond_signal to signal * the condition. */ os_result os_condSignal ( os_cond *cond) { return condSignal(cond, SIGNAL_BIT_MASK); }
/** \brief Signal the condition and wakeup all thread waiting * for the condition * * \b os_condBroadcast calls \b pthread_cond_broadcast to broadcast * the condition. */ void os_condBroadcast ( os_cond *cond) { condSignal(cond, BROADCAST_BIT_MASK); }
/** \brief Signal the condition and wakeup one thread waiting * for the condition * * \b os_condSignal calls \b pthread_cond_signal to signal * the condition. */ void os_condSignal ( os_cond *cond) { condSignal(cond, SIGNAL_BIT_MASK); }