pike.git / lib / modules / Sql.pmod / pgsql_util.pmod

version» Context lines:

pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:75: Inside #if PG_DEADLOCK_SENTINEL
   mutexes[this] = 1;    }   };   #else   #define MUTEX Thread.Mutex   #endif      //! The instance of the pgsql dedicated backend.   final Pike.Backend local_backend;    + private Shuffler.Shuffler shuffler = Shuffler.Shuffler();   private Pike.Backend cb_backend;   private Result qalreadyprinted;   private Thread.Mutex backendmux = Thread.Mutex();   final multiset(proxy) clients = set_weak_flag((<>), Pike.WEAK);      mapping describenodata    = (["datarowdesc":({}), "datarowtypes":({}), "datatypeoid":({})]);   private multiset censoroptions = (<"use_ssl", "force_ssl",    "cache_autoprepared_statements", "reconnect", "text_query", "is_superuser",    "server_encoding", "server_version", "integer_datetimes",
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:149:    = iregexp("^\a*((UPDA|DELE)TE|INSERT|CREATE|DROP|CALL"    "|RESET|CLOSE|DISCARD)\a|\aLIMIT\a+[1-9][; \t\f\r\n]*$");      private void default_backend_runs() { // Runs as soon as the    cb_backend = Pike.DefaultBackend; // DefaultBackend has started   }      protected void create() {    atexit(_destruct);    // Run callbacks from our local_backend until DefaultBackend has started -  cb_backend = local_backend = Pike.Backend(); +  shuffler->set_backend(cb_backend = local_backend = Pike.Backend());    call_out(default_backend_runs, 0);   }      protected void _destruct() {    foreach (clients; proxy client; )    destruct(client);   }      private Regexp iregexp(string expr) {    Stdio.Buffer ret = Stdio.Buffer();
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:478:       private Thread.Queue qportals;    final MUTEX shortmux;    private int closenext;       final sfile   #if constant(SSL.File)    |SSL.File   #endif    socket; +  final Shuffler.Shuffle shuffle;    final multiset(Result) runningportals = (<>);       final MUTEX nostash;    final Thread.MutexKey started;    final Thread.Queue stashqueue;    final Stdio.Buffer stash;    //! @ignore    final int(KEEP..SYNCSEND) stashflushmode;    //! @endignore    final Thread.ResourceCount stashcount;    final int synctransact;   #ifdef PG_DEBUGRACE    final mixed nostrack;   #endif   #ifdef PG_DEBUG    final int queueoutidx;    final int queueinidx = -1;   #endif    - #if PG_DEBUGHISTORY > 0 -  final int(-1..) output_to(Stdio.Stream stm, void|int(0..) nbytes) { -  Stdio.Buffer tb = Stdio.Buffer(this); -  int ret = o::output_to(stm, nbytes); -  if (ret) { -  i->history += ({">>" + tb->read(ret)}); -  i->history = i->history[<PG_DEBUGHISTORY - 1 ..]; -  } -  return ret; -  } - #endif -  +     private inline void queueup(Result portal) {    qportals->write(portal); portal->_synctransact = synctransact;    PD("%d>%O %d %d Queue portal %d bytes\n", socket->query_fd(),    portal._portalname, ++queueoutidx, synctransact, sizeof(this));    }       final bufcon|conxsess start(void|int|array(Thread.MutexKey) waitforreal) {    Thread.MutexKey lock;   #ifdef PG_DEBUGRACE    if (nostash->current_locking_thread())
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:551:    return sess;   #else    return this;   #endif    }    if (arrayp(waitforreal))    waitforreal[0] = 0;    return !waitforreal && bufcon(this)->start();    }    -  private int write_cb() { -  Thread.MutexKey lock = shortmux->lock(); +  private void done_cb() {    if (this) { // Guard against async destructs -  output_to(socket); -  lock = 0; -  if (!i->fillread && !sizeof(this)) +  if (!i->fillread)    close();    } -  return 0; +     }       private int getstash(int mode) {    Thread.MutexKey lock = shortmux->lock();    add(stash); stash->clear();    foreach (stashqueue->try_read_array(); ; int|Result portal)    if (intp(portal))    qportals->write(synctransact++);    else    queueup(portal);
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:621:    switch (mode) {    default:    PD("%d>Skip flush %d Queue %O\n",    socket->query_fd(), mode, (string)this);    break outer;    case FLUSHSEND:    PD("Flush\n");    add(PGFLUSH);    case SENDOUT:;    } -  Thread.MutexKey lock = shortmux->trylock(); -  if (lock && sizeof(this)) { +  if (sizeof(this)) {    PD("%d>Sendcmd %O\n", socket->query_fd(), (string)this); -  output_to(socket); + #if PG_DEBUGHISTORY > 0 +  i->history += ({">>" + (string)this}); +  i->history = i->history[<PG_DEBUGHISTORY - 1 ..]; + #endif +  shuffle->add_source(this); +  shuffle->start(1);    }    } while (0);    started = 0;    if (sizeof(stash) && (started = nostash->trylock(2))) {   #ifdef PG_DEBUGRACE    conxsess sess = conxsess(this);    sess->sendcmd(SENDOUT);   #else    mode = getstash(SENDOUT);    continue;
pike.git/lib/modules/Sql.pmod/pgsql_util.pmod:745:    error("Encryption library missing,"    " cannot establish connection to %s:%d\n",    pgsqlsess.host, pgsqlsess.port);   #endif    break;    }    if (!socket->is_open())    error(strerror(socket->errno()) + ".\n");    socket->set_backend(local_backend);    socket->set_buffer_mode(i, 0); -  socket->set_nonblocking(i->read_cb, write_cb, close); +  socket->set_nonblocking(i->read_cb, 0, close); +  (shuffle = shuffler->shuffle(socket))->set_done_callback(done_cb);    if (nossl != 2)    Thread.Thread(pgsqlsess->processloop, this);    return;    };    PD("Connect error %s\n", describe_backtrace(err));    catch(destruct(pgsqlsess->waitforauthready));    destruct(this);    }       protected string _sprintf(int type) {