int main() { UnlockQueue unlockQueue(1024); if(!unlockQueue.Initialize()) { return -1; } pthread_t consumer_tid, producer_tid; printf("multi thread test.......\n"); if(0 != pthread_create(&producer_tid, NULL, producer_proc, (void*)&unlockQueue)) { fprintf(stderr, "Failed to create consumer thread.errno:%u, reason:%s\n", errno, strerror(errno)); return -1; } if(0 != pthread_create(&consumer_tid, NULL, consumer_proc, (void*)&unlockQueue)) { fprintf(stderr, "Failed to create consumer thread.errno:%u, reason:%s\n", errno, strerror(errno)); return -1; } pthread_join(producer_tid, NULL); pthread_join(consumer_tid, NULL); return 0; }
void QueueManager::sortQueue(QueueType queue) { lockQueue(queue); _queue[queue].sort(queueComp); unlockQueue(queue); }
void CommandQueue::waitCycle() { if (lockQueue()) { executeCommands(); unlockQueue(); } }
void Renderable::show() { lockQueue(_queueVisible); addToQueue(_queueVisible); sortQueue(_queueVisible); unlockQueue(_queueVisible); }
void submitJob( IJob* job ) { m_jobQueue.push_back( job ); lockQueue(); m_tailIndex++; m_queueIsEmpty = false; unlockQueue(); }
void QueueManager::removeFromQueue(QueueType queue, const std::list<Queueable *>::iterator &ref) { lockQueue(queue); _queue[queue].erase(ref); unlockQueue(queue); }
void clearQueue() { lockQueue(); m_headIndex = 0; m_tailIndex = 0; m_queueIsEmpty = true; unlockQueue(); m_jobQueue.resizeNoInitialize( 0 ); }
std::list<Queueable *>::iterator QueueManager::addToQueue(QueueType queue, Queueable &q) { lockQueue(queue); _queue[queue].push_back(&q); std::list<Queueable *>::iterator ref = --_queue[queue].end(); unlockQueue(queue); return ref; }
void QueueManager::clearQueue(QueueType queue) { lockQueue(queue); for (std::list<Queueable *>::iterator q = _queue[queue].begin(); q != _queue[queue].end(); ++q) (*q)->kickedOut(queue); _queue[queue].clear(); unlockQueue(queue); }
// sets the maximum log lines captured for the final // display to the user on failure exit void log_captureLines (int num) { if (num > MAX_LOG_ENTRIES) num = MAX_LOG_ENTRIES; if (num < 1) num = 1; maxDisp = num; // remove any extra lines already on queue lockQueue (); removeExcess (0); unlockQueue (); }
static int acquireSlot (void) { int slot; lockQueue (); removeExcess (1); slot = qhead; qhead = (qhead + 1) % MAX_LOG_ENTRIES; ++qtotal; unlockQueue (); return slot; }
IJob* consumeJob() { if ( m_queueIsEmpty ) { // lock free path. even if this is taken erroneously it isn't harmful return NULL; } IJob* job = NULL; lockQueue(); if ( !m_queueIsEmpty ) { job = m_jobQueue[ m_headIndex++ ]; if ( m_headIndex == m_tailIndex ) { m_queueIsEmpty = true; } } unlockQueue(); return job; }