int Worker::move_task_to_ready_queue(TaskQueue_Item **qi) { //pthread_mutex_lock(&w_lock); pthread_mutex_lock(&lock); rqueue.push_back(*qi); //wqueue.erase(*qi); pthread_mutex_unlock(&lock); //pthread_mutex_unlock(&w_lock); }
// Insert tasks into queue without repeated fields //int32_t Worker::HB_insertQ_new(NoVoHT *map, Package &package) { void* HB_insertQ_new(void* args) { package_thread_args targs = *((package_thread_args*) args); queue<string*> *source = targs.source; TaskQueue *dest = targs.dest; pthread_mutex_t *slock = targs.slock; pthread_mutex_t *dlock = targs.dlock; Worker *worker = targs.worker; string *st; Package package; while (ON) { while (source->size() > 0) { pthread_mutex_lock(slock); if (source->size() > 0) { try { st = source->front(); source->pop(); //cout << "recd something" << endl; } catch (exception& e) { cout << "void* HB_insertQ_new: " << e.what() << endl; exit(1); } } else { pthread_mutex_unlock(slock); continue; } pthread_mutex_unlock(slock); package.ParseFromString(*st); delete st; TaskQueue_Item *qi; uint32_t task_recd_count = 0; string alltasks(package.realfullpath()); int num_vector_count, per_vector_count; vector<vector<string> > tokenize_string = tokenize(alltasks, '\"', '\'', num_vector_count, per_vector_count); //cout << "num_vector_count = " << num_vector_count << " per_vector_count = " << per_vector_count << endl; task_recd_count = num_vector_count; for (int i = 0; i < num_vector_count; i++) { qi = new TaskQueue_Item(); try { qi->task_id = tokenize_string.at(i).at(0); //cout << "insertq: qi->task_id = " << qi->task_id << endl; } catch (exception& e) { cout << "void* HB_insertQ_new: (tokenize_string.at(i).at(0)) " << " " << e.what() << endl; exit(1); } /*stringstream num_moves_ss; try { num_moves_ss << tokenize_string.at(i).at(1); } catch (exception& e) { cout << "void* HB_insertQ_new: (tokenize_string.at(i).at(0)) " << " " << e.what() << endl; exit(1); } num_moves_ss >> qi->num_moves;*/ if (LOGGING) { task_fp << " taskid = " << qi->task_id; //task_fp << " num moves = " << qi->num_moves; } pthread_mutex_lock(dlock); try { dest->push_back(qi); } catch (std::bad_alloc& exc) { cout << "HB_InsertQ_new: cannot allocate memory while adding element to ready queue" << endl; pthread_exit(NULL); } pthread_mutex_unlock(dlock); } if (LOGGING) { log_fp << "Num tasks received = " << task_recd_count << " Queue length = " << dest->size() << endl; } } } }