int CoreIOReader::ReadLine(char *_buffer, size_t _bufferLength) { CoreAssert(this != NULL); if (!IsOpen()) return CC_ERR_INVALID_BUFFER; if (!_buffer) return CC_ERR_INVALID_BUFFER; if (!_bufferLength) return CC_ERR_INVALID_BUFFER; #ifndef __GNUC__ MutexHolder mh(&m_ioMutex); #endif /* We use fgets because it detects line endings. */ _buffer[0] = '\x0'; char *ret = fgets(_buffer, (int)_bufferLength, m_fileInputPointer); if (ret != _buffer) return -1; /* Detect line endings. */ char *endl = NULL; char *cr = strchr(_buffer, '\r'); char *lf = strchr(_buffer, '\n'); char *crlf = strstr(_buffer, "\r\n"); if (crlf) { SetLineEndings(CC_LN_CRLF); endl = crlf; } else if (cr) { SetLineEndings(CC_LN_CR); endl = cr; } else if (lf) { SetLineEndings(CC_LN_LF); endl = lf; } if (endl) *endl = '\x0'; return (int)strlen(_buffer); }
/*END CVODE*/ static int states (double* _p, Datum* _ppvar, Datum* _thread, _NrnThread* _nt) { { mh ( _threadargscomma_ v ) ; m = m + (1. - exp(dt*(( ( ( - 1.0 ) ) ) / m_tau)))*(- ( ( ( m_inf ) ) / m_tau ) / ( ( ( ( - 1.0) ) ) / m_tau ) - m) ; h = h + (1. - exp(dt*(( ( ( - 1.0 ) ) ) / h_tau)))*(- ( ( ( h_inf ) ) / h_tau ) / ( ( ( ( - 1.0) ) ) / h_tau ) - h) ; } return 0; }
// TestExclusivity //------------------------------------------------------------------------------ void TestMutex::TestExclusivity() const { TestExclusivityUserData data; data.m_Count = 0; Thread::ThreadHandle h = Thread::CreateThread( TestExclusivityThreadEntryFunction, "TestExclusivity", ( 64 * KILOBYTE ), static_cast< void * >( &data ) ); // signal thread volatile uint32_t & sharedVar = data.m_Count; ++sharedVar; // increment for ( size_t i=0; i<1000000; ++i ) { MutexHolder mh( data.m_Mutex ); ++sharedVar; } // wait for other thread to complete bool timedOut = false; Thread::WaitForThread( h, 1000, timedOut ); TEST_ASSERT( timedOut == false ); Thread::CloseHandle( h ); // ensure total is correct TEST_ASSERT( sharedVar == 2000001 ); }
// FinishedProcessingJob (Worker Thread) //------------------------------------------------------------------------------ void JobQueueRemote::FinishedProcessingJob( Job * job, bool success ) { // ASSERT( job->GetNode()->GetState() == Node::BUILDING ); // remove from in-flight { MutexHolder mh( m_InFlightJobsMutex ); Job ** it = m_InFlightJobs.Find( job ); ASSERT( it != nullptr ); m_InFlightJobs.Erase( it ); } // handle jobs which were cancelled while in flight if ( job->GetUserData() == nullptr ) { FDELETE job; return; } // push to appropriate completion queue { MutexHolder m( m_CompletedJobsMutex ); if ( success ) { m_CompletedJobs.Append( job ); } else { m_CompletedJobsFailed.Append( job ); } } WakeMainThread(); }
/* TODO: This function uses fgetc() which incurs unnecessary function call overhead. Find a suitable replacement. */ int CoreIOReader::ReadLine(std::string &_string) { CoreAssert(this != NULL); if (!IsOpen()) return CC_ERR_INVALID_BUFFER; #ifndef __GNUC__ MutexHolder mh(&m_ioMutex); #endif char c = (char)fgetc(m_fileInputPointer); if (c == (char)EOF) return 0; std::string buffer; while (c != (char)EOF && c != '\n') { buffer += c; c = (char)fgetc(m_fileInputPointer); } int len = (int)buffer.length(); if (len && buffer[len - 1] == '\r') buffer.resize(len - 1); _string = buffer; return (int)_string.length() * sizeof(char); }
int save_restriction( void ) { int rv; EmacsBuffer *b = bf_cur; EmacsBuffer *b2; Marker ml( bf_cur, bf_cur->b_mode.md_headclip, 0); Marker mh( bf_cur, bf_cur->unrestrictedSize() + 1 - bf_cur->b_mode.md_tailclip, 1); rv = progn_command(); b2 = bf_cur; b->b_mode.md_headclip = ml.to_mark(); b->b_mode.md_tailclip = bf_cur->unrestrictedSize() + 1 - mh.to_mark(); if( dot < bf_cur->first_character() ) set_dot( bf_cur->first_character() ); if( dot > bf_cur->num_characters() ) set_dot( bf_cur->num_characters() + 1 ); if( bf_cur != b2 ) b2->set_bf(); cant_1win_opt = 1; return rv; }
// GetSynchronizationStatus //------------------------------------------------------------------------------ bool ToolManifest::GetSynchronizationStatus( uint32_t & syncDone, uint32_t & syncTotal ) const { syncDone = 0; syncTotal = 0; bool synching = false; MutexHolder mh( m_Mutex ); // is completely synchronized? const File * const end = m_Files.End(); for ( const File * it = m_Files.Begin(); it != end; ++it ) { syncTotal += it->m_ContentSize; if ( it->m_SyncState == File::SYNCHRONIZED ) { syncDone += it->m_ContentSize; } else if ( it->m_SyncState == File::SYNCHRONIZING ) { synching = true; } } return synching; }
// Reset //------------------------------------------------------------------------------ /*static*/ void MemTracker::Reset() { MutexHolder mh( GetMutex() ); ++g_MemTrackerDisabledOnThisThread; // free all allocation tracking for ( size_t i=0; i<ALLOCATION_HASH_SIZE; ++i ) { Allocation * a = s_AllocationHashTable[ i ]; while ( a ) { s_Allocations->Free( a ); --s_AllocationCount; a = a->m_Next; } s_AllocationHashTable[ i ] = nullptr; } ASSERT( s_AllocationCount == 0 ); s_Id = 0; --g_MemTrackerDisabledOnThisThread; }
CrissCross::Errors CoreIOWriter::Write(const char *_format, ...) { CoreAssert(this != NULL); if (!IsOpen()) return CC_ERR_INVALID_BUFFER; if (_format == NULL) return CC_ERR_BADPARAMETER; #ifndef __GNUC__ MutexHolder mh(&m_ioMutex); #endif va_list args; va_start(args, _format); /* Print out the string */ if (vfprintf(m_fileOutputPointer, _format, args) < 0) return CC_ERR_WRITE; fflush(m_fileOutputPointer); va_end(args); return CC_ERR_NONE; }
//------------------------------------------------------------------------------ /*virtual*/ void Client::OnDisconnected( const ConnectionInfo * connection ) { ASSERT( connection ); ServerState * ss = (ServerState *)connection->GetUserData(); ASSERT( ss ); MutexHolder mh( m_ServerListMutex ); if ( ss->m_Jobs.IsEmpty() == false ) { Job ** it = ss->m_Jobs.Begin(); const Job * const * end = ss->m_Jobs.End(); while ( it != end ) { JobQueue::Get().ReturnUnfinishedDistributableJob( *it ); ++it; } ss->m_Jobs.Clear(); } // This is usually null here, but might need to be freed if // we had the connection drop between message and payload FREE( (void *)( ss->m_CurrentMessage ) ); ss->m_Connection = nullptr; ss->m_CurrentMessage = nullptr; }
// GetStatus //------------------------------------------------------------------------------ void WorkerThreadRemote::GetStatus( AString & hostName, AString & status, bool & isIdle ) const { isIdle = false; MutexHolder mh( m_CurrentJobMutex ); if ( m_CurrentJob ) { Server::GetHostForJob( m_CurrentJob, hostName ); if ( IsEnabled() == false ) { status = "(Finishing) "; } status += m_CurrentJob->GetRemoteName(); } else { hostName.Clear(); if ( IsEnabled() == false ) { status = "(Disabled)"; } else { status = "Idle"; isIdle = true; } } }
void collect_profiled_methods(methodOop m) { methodHandle mh(Thread::current(), m); if ((m->method_data() != NULL) && (PrintMethodData || CompilerOracle::should_print(mh))) { collected_profiled_methods->push(m); } }
// JobSubQueue:QueueJobs //------------------------------------------------------------------------------ void JobSubQueue::QueueJobs( Array< Node * > & nodes ) { // Create wrapper Jobs around Nodes Array< Job * > jobs( nodes.GetSize() ); for ( Node * node : nodes ) { Job * job = FNEW( Job( node ) ); jobs.Append( job ); } // Sort Jobs by cost JobCostSorter sorter; jobs.Sort( sorter ); // lock to add job MutexHolder mh( m_Mutex ); const bool wasEmpty = m_Jobs.IsEmpty(); m_Jobs.Append( jobs ); m_Count += (uint32_t)jobs.GetSize(); if ( wasEmpty ) { return; // skip re-sorting } // sort merged lists m_Jobs.Sort( sorter ); }
int CoreIOReader::ReadU64(uint64_t *_buffer) { CoreAssert(this != NULL); if (!IsOpen()) return CC_ERR_INVALID_BUFFER; if (!_buffer) return CC_ERR_INVALID_BUFFER; #ifndef __GNUC__ MutexHolder mh(&m_ioMutex); #endif size_t retval; retval = fread(_buffer, sizeof(uint64_t), 1, m_fileInputPointer); switch (m_endianness) { case CC_ENDIAN_LITTLE: *_buffer = CC_SwapLE64(*_buffer); break; case CC_ENDIAN_BIG: *_buffer = CC_SwapBE64(*_buffer); break; case CC_ENDIAN_NATIVE: /* Do nothing */ break; } return retval; }
//------------------------------------------------------------------------------ /*virtual*/ void Client::OnDisconnected( const ConnectionInfo * connection ) { ASSERT( connection ); ServerState * ss = (ServerState *)connection->GetUserData(); ASSERT( ss ); MutexHolder mh( ss->m_Mutex ); DIST_INFO( "Disconnected: %s\n", ss->m_RemoteName.Get() ); if ( ss->m_Jobs.IsEmpty() == false ) { Job ** it = ss->m_Jobs.Begin(); const Job * const * end = ss->m_Jobs.End(); while ( it != end ) { FLOG_MONITOR( "FINISH_JOB TIMEOUT %s \"%s\" \n", ss->m_RemoteName.Get(), (*it)->GetNode()->GetName().Get() ); JobQueue::Get().ReturnUnfinishedDistributableJob( *it ); ++it; } ss->m_Jobs.Clear(); } // This is usually null here, but might need to be freed if // we had the connection drop between message and payload FREE( (void *)( ss->m_CurrentMessage ) ); ss->m_RemoteName.Clear(); ss->m_Connection = nullptr; ss->m_CurrentMessage = nullptr; }
// RemoveJob //------------------------------------------------------------------------------ Job * JobSubQueue::RemoveJob() { // lock-free early out if there are no jobs if ( m_Count == 0 ) { return nullptr; } // lock to remove job MutexHolder mh( m_Mutex ); // possible that job has been removed between job count check and mutex lock if ( m_Jobs.IsEmpty() ) { return nullptr; } ASSERT( m_Count ); --m_Count; Job * job = m_Jobs.Top(); m_Jobs.Pop(); return job; }
/*CVODE*/ static int _ode_spec1 (double* _p, Datum* _ppvar, Datum* _thread, _NrnThread* _nt) {int _reset = 0; { mh ( _threadargscomma_ v ) ; Dm = ( m_inf - m ) / m_tau ; Dh = ( h_inf - h ) / h_tau ; } return _reset; }
void new_data(const unsigned char* data, UInt32 numBytes) { MutexHolder mh(m_mutex); // Buffer at most 2 s of audio samples const size_t MAX_BUFFER = static_cast<size_t>(2*m_input_format.mBytesPerFrame*m_format.mSampleRate); assert(numBytes < MAX_BUFFER); if (m_buffer.size() + numBytes > MAX_BUFFER) { const size_t toRemove = my_min(m_buffer.size(), m_buffer.size()+numBytes-MAX_BUFFER); m_buffer.erase(m_buffer.begin(), m_buffer.begin() + toRemove); } m_buffer.insert(m_buffer.end(), data, data + numBytes); assert(m_buffer.size() <= MAX_BUFFER); if (m_outputProcState == kOff && m_buffer.size() >= m_min_buffer) { start_audio(); } }
// OnConnected //------------------------------------------------------------------------------ /*virtual*/ void Server::OnConnected( const ConnectionInfo * connection ) { ClientState * cs = FNEW( ClientState( connection ) ); connection->SetUserData( cs ); MutexHolder mh( m_ClientListMutex ); m_ClientList.Append( cs ); }
// Process( MsgNoJobAvailable ) //------------------------------------------------------------------------------ void Server::Process( const ConnectionInfo * connection, const Protocol::MsgNoJobAvailable * ) { // We requested a job, but the client didn't have any left ClientState * cs = (ClientState *)connection->GetUserData(); MutexHolder mh( cs->m_Mutex ); ASSERT( cs->m_NumJobsRequested > 0 ); cs->m_NumJobsRequested--; }
Cvirtual_binary Cfile32::get_mm() { if (!size()) return Cvirtual_binary(); Cwin_handle mh(CreateFileMapping(h(), NULL, PAGE_READONLY, 0, 0, NULL)); void* d = mh ? MapViewOfFile(mh, FILE_MAP_READ, 0, 0, 0) : NULL; return d ? Cvirtual_binary(d, size(), std::shared_ptr<void>(d, UnmapViewOfFile)) : Cvirtual_binary(); }
void ServerWorker::_sendBindReply( const bool successful ) { MessageHeader mh( MESSAGE_TYPE_BIND_EVENTS_REPLY, sizeof( bool )); _send( mh ); _tcpSocket->write( (const char *)&successful, sizeof( bool )); _flushSocket(); }
// this function computes the vtable size (including the size needed for miranda // methods) and the number of miranda methods in this class // Note on Miranda methods: Let's say there is a class C that implements // interface I. Let's say there is a method m in I that neither C nor any // of its super classes implement (i.e there is no method of any access, with // the same name and signature as m), then m is a Miranda method which is // entered as a public abstract method in C's vtable. From then on it should // treated as any other public method in C for method over-ride purposes. void klassVtable::compute_vtable_size_and_num_mirandas(int &vtable_length, int &num_miranda_methods, klassOop super, objArrayOop methods, AccessFlags class_flags, Handle classloader, Symbol* classname, objArrayOop local_interfaces, TRAPS ) { No_Safepoint_Verifier nsv; // set up default result values vtable_length = 0; num_miranda_methods = 0; // start off with super's vtable length instanceKlass* sk = (instanceKlass*)super->klass_part(); vtable_length = super == NULL ? 0 : sk->vtable_length(); // go thru each method in the methods table to see if it needs a new entry int len = methods->length(); for (int i = 0; i < len; i++) { assert(methods->obj_at(i)->is_method(), "must be a methodOop"); methodHandle mh(THREAD, methodOop(methods->obj_at(i))); if (needs_new_vtable_entry(mh, super, classloader, classname, class_flags, THREAD)) { vtable_length += vtableEntry::size(); // we need a new entry } } // compute the number of mirandas methods that must be added to the end num_miranda_methods = get_num_mirandas(super, methods, local_interfaces); vtable_length += (num_miranda_methods * vtableEntry::size()); if (Universe::is_bootstrapping() && vtable_length == 0) { // array classes don't have their superclass set correctly during // bootstrapping vtable_length = Universe::base_vtable_size(); } if (super == NULL && !Universe::is_bootstrapping() && vtable_length != Universe::base_vtable_size()) { // Someone is attempting to redefine java.lang.Object incorrectly. The // only way this should happen is from // SystemDictionary::resolve_from_stream(), which will detect this later // and throw a security exception. So don't assert here to let // the exception occur. vtable_length = Universe::base_vtable_size(); } assert(super != NULL || vtable_length == Universe::base_vtable_size(), "bad vtable size for class Object"); assert(vtable_length % vtableEntry::size() == 0, "bad vtable length"); assert(vtable_length >= Universe::base_vtable_size(), "vtable too small"); }
int read(unsigned char* data, int num_samples) { MutexHolder mh(m_mutex); // m_logger(2, "Read request..."); if (m_outputProcState == kRunning && m_buffer.size() < num_samples * m_input_format.mBytesPerFrame) { stop_audio(); return 0; } const UInt32 inputDataSizeBytes = my_min(num_samples * m_input_format.mBytesPerFrame, m_buffer.size()); std::vector<unsigned char> input_data(m_buffer.begin(), m_buffer.begin() + inputDataSizeBytes); m_buffer.erase(m_buffer.begin(), m_buffer.begin() + inputDataSizeBytes); int outputDataSizeBytes = num_samples*m_format.mBytesPerFrame; OSStatus err; err = m_converter->convert(&input_data[0], input_data.size(), data, outputDataSizeBytes); if (err != kAudioHardwareNoError) { char buf[1024] = {0}; sprintf(buf, "Conversion failed, num_samples=%i, inputDataSize = %i\n" "buffer_size = %i, outputDataSize = %i (err=0x%lX (= %i))", num_samples, inputDataSizeBytes, m_buffer.size(), outputDataSizeBytes, err, err); m_logger(0, buf); return 0; } /* char buf[512] = {0}; sprintf(buf, "Converted %i bytes to %i bytes (num_samples=%i)", inputDataSizeBytes, outputDataSizeBytes, num_samples); m_logger(2, buf);*/ return outputDataSizeBytes / m_format.mBytesPerFrame; }
void ModbusAddress::update(MachineInstance *owner, Group group, int addr, int new_value, int len) { std::list<Value>params; params.push_back(group); params.push_back(addr); params.push_back(Value(name.c_str(),Value::t_string)); params.push_back(len); params.push_back(new_value); MessageHeader mh(MessageHeader::SOCK_CW, MessageHeader::SOCK_CW, false); Channel::sendCommand(owner, "UPDATE", ¶ms, mh); }
static void initmodel(double* _p, Datum* _ppvar, Datum* _thread, _NrnThread* _nt) { int _i; double _save;{ n = n0; { mh ( _threadargscomma_ cai ) ; n = n_inf ; } } }
void CoreIOReader::Flush() { CoreAssert(this != NULL); if (!IsOpen()) return; #ifndef __GNUC__ MutexHolder mh(&m_ioMutex); #endif fflush(m_fileInputPointer); }
static void _hoc_mh(void) { double _r; double* _p; Datum* _ppvar; Datum* _thread; _NrnThread* _nt; if (_extcall_prop) {_p = _extcall_prop->param; _ppvar = _extcall_prop->dparam;}else{ _p = (double*)0; _ppvar = (Datum*)0; } _thread = _extcall_thread; _nt = nrn_threads; _r = 1.; mh ( _p, _ppvar, _thread, _nt, *getarg(1) ); hoc_retpushx(_r); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); QCoreApplication::setOrganizationName("gambatte"); QCoreApplication::setApplicationName("gambatte_qt"); GambatteSource source; MainWindow mw(source); GambatteMenuHandler mh(mw, source, argc, argv); mw.show(); return app.exec(); }
static void initmodel(double* _p, Datum* _ppvar, Datum* _thread, _NrnThread* _nt) { int _i; double _save;{ h = h0; m = m0; { mh ( _threadargscomma_ v ) ; m = m_inf ; h = h_inf ; } } }