OP_STATUS ES_Thread::DecBlockedByForeignThread() { if (--blocked_by_foreign_thread == 0) { if (block_type == ES_BLOCK_FOREIGN_THREAD) return Unblock(ES_BLOCK_FOREIGN_THREAD); } return OpStatus::OK; }
void Unblock_waiting_for_me(TCB* thread) { TCB_list_node* pointer = (thread->waiting_for_me)->front; while(pointer != NULL) { Unblock(pointer->data, thread); pointer = pointer->next; } }
virtual void PauseProgress(wxCommandEvent& event) { if (!paused) { Block(); paused = true; OSPause->SetLabel("Unpause"); } else { Unblock(); paused = false; OSPause->SetLabel("Pause"); } }
/// <summary> /// Queues a thread to execute to completion and asynchronously returns. /// </summary> /// <param name="pProxy"> /// The proxy to queue to completion. /// </param> void TransmogrifiedPrimary::QueueToCompletion(UMSThreadProxy *pProxy) { // We need to use a hypercritical lock here since // this is called from the primary as well. UMSThreadProxy *pCurrentProxy = UMSThreadProxy::GetCurrent(); if (pCurrentProxy != NULL) { pCurrentProxy->EnterHyperCriticalRegion(); } m_queuedExecutions.Enqueue(pProxy); if (pCurrentProxy != NULL) { pCurrentProxy->ExitHyperCriticalRegion(); } if (InterlockedIncrement(&m_queueCount) == 1) { Unblock(); } }
void Castle::GenerateRoom(int k_room, int x, int y, int z) { if(++ room_count_[room_.size() - 1] > k_room_ * 5) { int n = Unblock(); /* Print(); if(!n) { map<vector<int>, int> temp; vector<int> coordinate(3); for(vector<Room>::iterator it = room_.begin() + 1; it != room_.end(); it++) { coordinate[0] = it->coordinate(0); coordinate[1] = it->coordinate(1); coordinate[2] = it->coordinate(2); temp[coordinate] = 1; } for(int i = min_.x ; i <= max_.x; i++) for(int j = min_.y ; j <= max_.y; j++) for(int k = min_.z ; k <= max_.z; k++) { coordinate[0] = i; coordinate[1] = j; coordinate[2] = k; if(!temp[coordinate]) cout << i << " " << j << " " << k << " " << room_index_[coordinate] << " " << OneNeighbor(i, j, k) << endl; } } assert(n);*/ k_room--; x = room_[n].coordinate_x(); y = room_[n].coordinate_y(); z = room_[n].coordinate_z(); // Print(); // Run(); } vector<int> coordinate(3); coordinate[0] = x; coordinate[1] = y; coordinate[2] = z; // int m = MaxDoor(x, y, z); // if(!m) return; // int k = rand() % min(m, k_room) + 1; int n = room_index_[coordinate]; int left = k_room; int a[7] = {0, 1, 2, 3, 4, 5}; int j; for(int i = 0; i < 6; i++) { j = rand() % 6; a[6] = a[i]; a[i] = a[j]; a[j] = a[6]; } j = 5; while(left) { j = (j + 1) % 6; coordinate[0] = x; coordinate[1] = y; coordinate[2] = z; switch(a[j]) { case 0: coordinate[1] = y + 1; break; case 1: coordinate[1] = y - 1; break; case 2: coordinate[0] = x - 1; break; case 3: coordinate[0] = x + 1; break; case 4: coordinate[2] = z + 1; break; case 5: coordinate[2] = z - 1; break; } int l = rand() % (left + 1); if(!l) continue; int nn = room_index_[coordinate]; if(nn) { if(!room_[n].door(a[j]) && room_[n].k_door_max() > room_[n].k_door() && room_[nn].k_door_max() > room_[nn].k_door() && rand() % 6 == 0) { room_[n].door(a[j], nn); room_[n].k_door(room_[n].k_door() + 1); room_[nn].door(a[j] ^ 1, n); room_[nn].k_door(room_[nn].k_door() + 1); } if(room_[n].door(a[j])) { // cout << n << " *> " << nn << " l: " << l << " left: " << left - l << endl; GenerateRoom(l, coordinate[0], coordinate[1], coordinate[2]); left -= l; } } else if(Valid(coordinate[0], coordinate[1], coordinate[2]) && room_[n].k_door_max() > room_[n].k_door()) { nn = room_.size(); room_index_[coordinate] = nn; room_[n].door(a[j], nn); room_[n].k_door(room_[n].k_door() + 1); Room room(coordinate[0], coordinate[1], coordinate[2], rand() % MaxDoor(coordinate[0], coordinate[1], coordinate[2]) + 1); room.door(a[j] ^ 1, n); room_.push_back(room); // cout << "room: " << n << " new: " << nn << endl; // cout << n << " -> " << nn << " l: " << l - 1 << " left: " << left - l << endl; if(l - 1) GenerateRoom(l - 1, coordinate[0], coordinate[1], coordinate[2]); left -= l; } } }