/ Check-in [df66fec9]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use a fast compiler-provided memory barrier exclusively, if such a memory barrier is available.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | faster-memory-barrier
Files: files | file ages | folders
SHA3-256: df66fec9bc5b8c012d2fef3e97b3f7c3850a195b417806bfddc00b88e99c97d7
User & Date: drh 2019-02-08 20:55:16
Context
2019-02-08
20:55
Use a fast compiler-provided memory barrier exclusively, if such a memory barrier is available. Leaf check-in: df66fec9 user: drh tags: faster-memory-barrier
17:28
Further simplifications to sqlite3VdbeMemSetStr(). check-in: 1d212957 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/mutex_unix.c.

    89     89   ** where SQLite is compiled without mutexes.
    90     90   */
    91     91   void sqlite3MemoryBarrier(void){
    92     92   #if defined(SQLITE_MEMORY_BARRIER)
    93     93     SQLITE_MEMORY_BARRIER;
    94     94   #elif defined(__GNUC__) && GCC_VERSION>=4001000
    95     95     __sync_synchronize();
           96  +# define sqlite3MemoryBarrier_IS_RELIABLE 1
    96     97   #endif
    97     98   }
    98     99   
    99    100   /*
   100    101   ** Initialize and deinitialize the mutex subsystem.
   101    102   */
   102    103   static int pthreadMutexInit(void){ return SQLITE_OK; }

Changes to src/mutex_w32.c.

    83     83   ** compiled without mutexes (SQLITE_THREADSAFE=0).
    84     84   */
    85     85   void sqlite3MemoryBarrier(void){
    86     86   #if defined(SQLITE_MEMORY_BARRIER)
    87     87     SQLITE_MEMORY_BARRIER;
    88     88   #elif defined(__GNUC__)
    89     89     __sync_synchronize();
           90  +# define sqlite3MemoryBarrier_IS_RELIABLE 1
    90     91   #elif MSVC_VERSION>=1300
    91     92     _ReadWriteBarrier();
           93  +# define sqlite3MemoryBarrier_IS_RELIABLE 1
    92     94   #elif defined(MemoryBarrier)
    93     95     MemoryBarrier();
    94     96   #endif
    95     97   }
    96     98   
    97     99   /*
    98    100   ** Initialize and deinitialize the mutex subsystem.

Changes to src/os_unix.c.

  4889   4889     sqlite3_file *fd                /* Database file holding the shared memory */
  4890   4890   ){
  4891   4891     UNUSED_PARAMETER(fd);
  4892   4892     sqlite3MemoryBarrier();         /* compiler-defined memory barrier */
  4893   4893     assert( fd->pMethods->xLock==nolockLock 
  4894   4894          || unixFileMutexNotheld((unixFile*)fd) 
  4895   4895     );
         4896  +#ifndef sqlite3MemoryBarrier_IS_RELIABLE
  4896   4897     unixEnterMutex();               /* Also mutex, for redundancy */
  4897   4898     unixLeaveMutex();
         4899  +#endif
  4898   4900   }
  4899   4901   
  4900   4902   /*
  4901   4903   ** Close a connection to shared-memory.  Delete the underlying 
  4902   4904   ** storage if deleteFlag is true.
  4903   4905   **
  4904   4906   ** If there is no shared memory associated with the connection then this

Changes to src/os_win.c.

  4170   4170   ** any load or store begun after the barrier.
  4171   4171   */
  4172   4172   static void winShmBarrier(
  4173   4173     sqlite3_file *fd          /* Database holding the shared memory */
  4174   4174   ){
  4175   4175     UNUSED_PARAMETER(fd);
  4176   4176     sqlite3MemoryBarrier();   /* compiler-defined memory barrier */
         4177  +#ifndef sqlite3MemoryBarrier_IS_RELIABLE
  4177   4178     winShmEnterMutex();       /* Also mutex, for redundancy */
  4178   4179     winShmLeaveMutex();
         4180  +#endif
  4179   4181   }
  4180   4182   
  4181   4183   /*
  4182   4184   ** This function is called to obtain a pointer to region iRegion of the
  4183   4185   ** shared-memory associated with the database file fd. Shared-memory regions
  4184   4186   ** are numbered starting from zero. Each shared-memory region is szRegion
  4185   4187   ** bytes in size.