static void addTempFile(std::string const & filename) { lock.lock(); setupUnlocked(); tmpfilenames.push_back(filename); lock.unlock(); }
void write(iterator sa, iterator se) { lock.lock(); // wait for free context if all buffers are in use if ( high-low == numbuffers ) { aiocb *waitlist[1] = { &contexts[low%numbuffers] }; aio_suspend (waitlist,1,0); low++; } uint64_t const len = se-sa; buffers[high % numbuffers] = ::libmaus::autoarray::AutoArray<char>(len); std::copy ( sa, se, buffers[high%numbuffers].get() ); memset ( &contexts[high%numbuffers], 0, sizeof(aiocb) ); contexts[high%numbuffers].aio_fildes = fd; contexts[high%numbuffers].aio_buf = buffers[high % numbuffers].get(); contexts[high%numbuffers].aio_nbytes = len; contexts[high%numbuffers].aio_offset = 0; contexts[high%numbuffers].aio_sigevent.sigev_notify = SIGEV_NONE; aio_write( & contexts[high%numbuffers] ); high++; lock.unlock(); }
static uint64_t addPipeHandler(SignalHandler * handler) { lock.lock(); uint64_t const id = sigpipehandlers.size() ? (sigpipehandlers.rbegin()->first+1) : 0; sigpipehandlers[id] = handler; lock.unlock(); return id; }
void write(iterator sa, iterator se) { lock.lock(); ::libmaus::autoarray::AutoArray<char> buf(se-sa); std::copy(sa,se,buf.get()); ostr.write(buf.get(),se-sa); lock.unlock(); }
static void removeAllHandler(uint64_t const id) { lock.lock(); siginthandlers.erase(siginthandlers.find(id)); sigtermhandlers.erase(sigtermhandlers.find(id)); sighuphandlers.erase(sighuphandlers.find(id)); sigpipehandlers.erase(sigpipehandlers.find(id)); lock.unlock(); }
static void setup() { lock.lock(); if ( ! setupComplete ) { setupTempFileRemovalRoutines(); setupComplete = true; } lock.unlock(); }
static uint64_t addAllHandler(SignalHandler * handler) { lock.lock(); uint64_t const pipeid = sigpipehandlers.size() ? (sigpipehandlers.rbegin()->first+1) : 0; uint64_t const hupid = sighuphandlers.size() ? (sighuphandlers.rbegin()->first+1) : 0; uint64_t const termid = sigtermhandlers.size() ? (sigtermhandlers.rbegin()->first+1) : 0; uint64_t const intid = siginthandlers.size() ? (siginthandlers.rbegin()->first+1) : 0; uint64_t const allid = std::max(std::max(pipeid,hupid),std::max(termid,intid)); siginthandlers[allid] = handler; sigtermhandlers[allid] = handler; sighuphandlers[allid] = handler; sigpipehandlers[allid] = handler; lock.unlock(); return allid; }
static void removePipeHandler(uint64_t const id) { lock.lock(); sigpipehandlers.erase(sigpipehandlers.find(id)); lock.unlock(); }
static void removeHupHandler(uint64_t const id) { lock.lock(); sighuphandlers.erase(sighuphandlers.find(id)); lock.unlock(); }
static void removeTermHandler(uint64_t const id) { lock.lock(); sigtermhandlers.erase(sigtermhandlers.find(id)); lock.unlock(); }
static void setup() { lock.lock(); setupUnlocked(); lock.unlock(); }
// insert value and return count after insertion void insert(key_type const v, uint64_t const w) { uint64_t const p0 = hash(v); uint64_t p = p0; // uint64_t loopcnt = 0; do { // position in use? if ( H[p].first != base_type::unused() ) { // value already present if ( H[p].first == v ) { H[p].second = w; return; } // in use but by other value (collision) else { p = displace(p,v); } } // position is not currently in use, try to get it else { #if defined(LIBMAUS_HAVE_SYNC_OPS) bool const ok = __sync_bool_compare_and_swap ( &(H[p].first), base_type::unused(), v); #else hlock.lock(); bool const ok = (H[p].first == base_type::unused()); if ( ok ) H[p].first = v; hlock.unlock(); #endif assert ( H[p].first != base_type::unused() ); // got it if ( H[p].first == v ) { // if this inserted the value, then increment fill if ( ok ) { #if defined(LIBMAUS_HAVE_SYNC_OPS) __sync_fetch_and_add(&fill,1); #else clock.lock(); fill++; clock.unlock(); #endif } H[p].second = w; return; } // someone else snapped position p before we got it else { p = displace(p,v); } } } while ( p != p0 ); ::libmaus::exception::LibMausException se; se.getStream() << "SimpleHashMap::insert(): unable to insert, table is full." << std::endl; se.finish(); throw se; }
/** * flush output file **/ void flush() { lock.lock(); ostr.flush(); lock.unlock(); }