bool InflatedHeader::update(STATE, HeaderWord header) { // Gain exclusive access to the insides of the InflatedHeader. utilities::thread::Mutex::LockGuard lg(mutex_); flags_ = header.f; switch(flags_.meaning) { case eAuxWordEmpty: return true; case eAuxWordObjID: object_id_ = flags_.aux_word; flags_.meaning = eAuxWordEmpty; flags_.aux_word = 0; return true; case eAuxWordLock: { assert(owner_id_ == 0); uint32_t tid = header.f.aux_word >> cAuxLockTIDShift; uint32_t count = header.f.aux_word & cAuxLockRecCountMask; initialize_mutex(tid, count); } return true; case eAuxWordHandle: handle_ = state->shared().global_handles()->find_index(state, flags_.aux_word); flags_.meaning = eAuxWordEmpty; flags_.aux_word = 0; return true; // Unsupported state, abort. default: return false; } }
ring_buffer_implementation(size_t capacity, ring_buffer* parent) throw (ring_buffer_concurrency_error_exception, ring_buffer_out_of_memory_exception) : capacity(capacity), _read(0), _write(0), parent(parent) { initialize_mutex(this); read_callback.callback = write_callback.callback = 0; if (0 == (buffer = malloc(capacity))) { destroy_mutex(this); throw ring_buffer_out_of_memory_exception(); } }
ring_buffer_implementation(ring_buffer_implementation* other, ring_buffer* parent) throw (ring_buffer_concurrency_error_exception, ring_buffer_out_of_memory_exception) : capacity(other->capacity), _read(other->_read), _write(other->_write), read_callback(other->read_callback), write_callback(other->write_callback), parent(parent) { lock_guard lock(other); initialize_mutex(this); if (0 != (buffer = malloc(capacity))) memcpy(buffer, other->buffer, capacity); else { destroy_mutex(this); throw ring_buffer_out_of_memory_exception(); } }
void simulate(int spc, int sbs, float intrvl) { pthread_t threads[3]; /*Manager(position = 0), Printer(position = 1) and Timer(position = 2)*/ Thread args[3]; /*Arguments of the pthreads*/ char hand[30]; total_page_substitutions = 0; /*Check if information of the processes are valid*/ if(!valid_process_information()) return; /*Initialize semaphore 'safe_access' to protect memory file access and free lists*/ if(!initialize_mutex()) return; /*Assign roles to threads*/ assign_thread_roles(args, spc, sbs, intrvl); /*Initialize page table*/ if(virtual % PAGE_SIZE == 0 && total % PAGE_SIZE == 0) initialize_page_table(); else {
/** * @fn THRET accept_thread(void *arg) * @brief The accepting thread for TCP connection. * @param[in] arg The argument of accepting thread: CONN_BCAP_SERVER. */ static THRET THTYPE accept_thread(void *arg) { #if !defined(THRET) THRET ret = (THRET)NULL; #endif int client; HRESULT hr; volatile struct CONN_BCAP_SERVER *child; struct CONN_BCAP_SERVER *bcap_param = (struct CONN_BCAP_SERVER *) arg; MUTEX mutex; /* Initializes mutex */ bcap_param->relation_mutex = &mutex; hr = initialize_mutex(&mutex); if(FAILED(hr)) goto exit_proc; while(1) { hr = wait_event(&bcap_param->term_main_evt, 300); if(SUCCEEDED(hr)) { break; } if(bcap_param->num_child < BCAP_CLIENT_MAX) { hr = tcp_accept(bcap_param->device.sock, &client); if(SUCCEEDED(hr)) { /* Sets no delay option */ tcp_set_nodelay(client, 1); /* Sets keep alive option */ tcp_set_keepalive(client, KEEPALIVE_ENABLE, KEEPALIVE_IDLE, KEEPALIVE_INTERVAL, KEEPALIVE_COUNT); /* Adds child */ change_relation(bcap_param, ADD_CHILD, &client); } } /* Deletes child */ change_relation(bcap_param, DELETE_CHILD, NULL); } exit_proc: /* Ends all children thread */ child = bcap_param->node1; while(child != NULL) { set_event((EVENT *) &child->term_main_evt); exit_thread(child->main_thread); child = bcap_param->node1; } /* Deletes child */ change_relation(bcap_param, DELETE_CHILD, NULL); /* Releases mutex */ release_mutex(&mutex); #if !defined(THRET) return ret; #endif }
// create new uuid from string void create (char const* str, size_t len = 0) const { initialize_mutex(); boost::mutex::scoped_lock lock(mutex_instance()); from_string(uuid_, str); }
// create new uuid from scratch void create (void) const { initialize_mutex(); boost::mutex::scoped_lock lock(mutex_instance()); uuid_ = uuid_generator_instance()(); }