403Webshell
Server IP : 172.67.216.182  /  Your IP : 172.68.164.63
Web Server : Apache
System : Linux krdc-ubuntu-s-2vcpu-4gb-amd-blr1-01.localdomain 5.15.0-142-generic #152-Ubuntu SMP Mon May 19 10:54:31 UTC 2025 x86_64
User : www ( 1000)
PHP Version : 7.4.33
Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /www/server/mysql/src/sql/auth/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /www/server/mysql/src/sql/auth/partitioned_rwlock.h
#ifndef PARTITIONED_RWLOCK_INCLUDED
#define PARTITIONED_RWLOCK_INCLUDED

/* Copyright (c) 2015, 2023, Oracle and/or its affiliates.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License, version 2.0,
   as published by the Free Software Foundation.

   This program is also distributed with certain software (including
   but not limited to OpenSSL) that is licensed under separate terms,
   as designated in a particular file or component or in included license
   documentation.  The authors of MySQL hereby grant you an additional
   permission to link the program and your derivative works with the
   separately licensed software that they have included with MySQL.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License, version 2.0, for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA */

#include "mysql/psi/mysql_thread.h"

/**
  Implementation of read-write lock partitioned by thread id.

  This rwlock provides better scalability in read-heavy environments by
  employing the following simple trick:
  *) Read lock is acquired only on one of its partitions. The specific
     partition is chosen according to thread id.
  *) Write lock is acquired on all partitions.

  This way concurrent request for read lock made by different threads
  have a good chance not to disturb each other by doing cache invalidation
  and atomic operations. As result scalability in this scenario improves.
  OTOH acquisition of write lock becomes more expensive. So this rwlock
  is not supposed to be used in cases when number of write requests is
  significant.
*/

class Partitioned_rwlock
{
public:
  Partitioned_rwlock() {}

  /**
    @param parts    Number of partitions.
    @param psi_key  P_S instrumentation key to use for rwlock instances
                    for partitions.
  */
  bool init(uint parts
#ifdef HAVE_PSI_INTERFACE
            , PSI_rwlock_key psi_key
#endif
            )
  {
    m_parts= parts;
    if (!(m_locks_array= new (std::nothrow) mysql_rwlock_t[m_parts]))
      return true;
    for (uint i= 0 ; i < m_parts; ++i)
      mysql_rwlock_init(psi_key, &m_locks_array[i]);
    return false;
  }
  void destroy()
  {
    for (uint i= 0 ; i < m_parts; ++i)
      mysql_rwlock_destroy(&m_locks_array[i]);
    delete [] m_locks_array;
  }
  void wrlock()
  {
    for (uint i= 0 ; i < m_parts; ++i)
      mysql_rwlock_wrlock(&m_locks_array[i]);
  }
  void wrunlock()
  {
    for (uint i= 0 ; i < m_parts; ++i)
      mysql_rwlock_unlock(&m_locks_array[i]);
  }
  void rdlock(uint thread_id)
  {
    mysql_rwlock_rdlock(&m_locks_array[thread_id%m_parts]);
  }
  /*
    One should use the same thread number for releasing read lock
    as was used for acquiring it,
  */
  void rdunlock(uint thread_id)
  {
    mysql_rwlock_unlock(&m_locks_array[thread_id%m_parts]);
  }

private:
  mysql_rwlock_t* m_locks_array;
  uint m_parts;

  Partitioned_rwlock(const Partitioned_rwlock&);            // Non-copyable
  Partitioned_rwlock& operator=(const Partitioned_rwlock&); // Non-copyable
};


/**
  Read lock guard class for Partitioned_rwlock. Supports early unlocking.
*/

class Partitioned_rwlock_read_guard
{
public:
  /**
    Acquires read lock on partitioned rwlock on behalf of thread.
    Automatically release lock in destructor.
  */
  Partitioned_rwlock_read_guard(Partitioned_rwlock *rwlock, uint thread_id)
    : m_rwlock(rwlock), m_thread_id(thread_id)
  {
    m_rwlock->rdlock(m_thread_id);
  }

  ~Partitioned_rwlock_read_guard()
  {
    if (m_rwlock)
      m_rwlock->rdunlock(m_thread_id);
  }

  /** Release read lock. Optional method for early unlocking. */
  void unlock()
  {
    m_rwlock->rdunlock(m_thread_id);
    m_rwlock= NULL;
  }

private:
  /**
    Pointer to partitioned rwlock which was acquired. NULL if lock was
    released early so destructor should not do anything.
  */
  Partitioned_rwlock *m_rwlock;
  /**
    Id of thread on which behalf lock was acquired and which is to be used for
    unlocking.
  */
  uint m_thread_id;

  // Non-copyable
  Partitioned_rwlock_read_guard(const Partitioned_rwlock_read_guard&);
  Partitioned_rwlock_read_guard& operator=(const
                                           Partitioned_rwlock_read_guard&);
};


/**
  Write lock guard class for Partitioned_rwlock. Supports early unlocking.
*/

class Partitioned_rwlock_write_guard
{
public:
  /**
    Acquires write lock on partitioned rwlock.
    Automatically release it in destructor.
  */
  explicit Partitioned_rwlock_write_guard(Partitioned_rwlock *rwlock)
    : m_rwlock(rwlock)
  {
    m_rwlock->wrlock();
  }

  ~Partitioned_rwlock_write_guard()
  {
    if (m_rwlock)
      m_rwlock->wrunlock();
  }

  /** Release write lock. Optional method for early unlocking. */
  void unlock()
  {
    m_rwlock->wrunlock();
    m_rwlock= NULL;
  }

private:
  /**
    Pointer to partitioned rwlock which was acquired. NULL if lock was
    released early so destructor should not do anything.
  */
  Partitioned_rwlock *m_rwlock;

  // Non-copyable
  Partitioned_rwlock_write_guard(const Partitioned_rwlock_write_guard&);
  Partitioned_rwlock_write_guard& operator=(const
                                            Partitioned_rwlock_write_guard&);
};

#endif /* PARTITIONED_RWLOCK_INCLUDED */

Youez - 2016 - github.com/yon3zu
LinuXploit