/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/mutex_unix.c.

89
90
91
92
93
94
95

96
97
98
99
100
101
102
** where SQLite is compiled without mutexes.
*/
void sqlite3MemoryBarrier(void){
#if defined(SQLITE_MEMORY_BARRIER)
  SQLITE_MEMORY_BARRIER;
#elif defined(__GNUC__) && GCC_VERSION>=4001000
  __sync_synchronize();

#endif
}

/*
** Initialize and deinitialize the mutex subsystem.
*/
static int pthreadMutexInit(void){ return SQLITE_OK; }







>







89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
** where SQLite is compiled without mutexes.
*/
void sqlite3MemoryBarrier(void){
#if defined(SQLITE_MEMORY_BARRIER)
  SQLITE_MEMORY_BARRIER;
#elif defined(__GNUC__) && GCC_VERSION>=4001000
  __sync_synchronize();
# define sqlite3MemoryBarrier_IS_RELIABLE 1
#endif
}

/*
** Initialize and deinitialize the mutex subsystem.
*/
static int pthreadMutexInit(void){ return SQLITE_OK; }

Changes to src/mutex_w32.c.

83
84
85
86
87
88
89

90
91

92
93
94
95
96
97
98
** compiled without mutexes (SQLITE_THREADSAFE=0).
*/
void sqlite3MemoryBarrier(void){
#if defined(SQLITE_MEMORY_BARRIER)
  SQLITE_MEMORY_BARRIER;
#elif defined(__GNUC__)
  __sync_synchronize();

#elif MSVC_VERSION>=1300
  _ReadWriteBarrier();

#elif defined(MemoryBarrier)
  MemoryBarrier();
#endif
}

/*
** Initialize and deinitialize the mutex subsystem.







>


>







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

/*
** Initialize and deinitialize the mutex subsystem.

Changes to src/os_unix.c.

4889
4890
4891
4892
4893
4894
4895

4896
4897

4898
4899
4900
4901
4902
4903
4904
  sqlite3_file *fd                /* Database file holding the shared memory */
){
  UNUSED_PARAMETER(fd);
  sqlite3MemoryBarrier();         /* compiler-defined memory barrier */
  assert( fd->pMethods->xLock==nolockLock 
       || unixFileMutexNotheld((unixFile*)fd) 
  );

  unixEnterMutex();               /* Also mutex, for redundancy */
  unixLeaveMutex();

}

/*
** Close a connection to shared-memory.  Delete the underlying 
** storage if deleteFlag is true.
**
** If there is no shared memory associated with the connection then this







>


>







4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
  sqlite3_file *fd                /* Database file holding the shared memory */
){
  UNUSED_PARAMETER(fd);
  sqlite3MemoryBarrier();         /* compiler-defined memory barrier */
  assert( fd->pMethods->xLock==nolockLock 
       || unixFileMutexNotheld((unixFile*)fd) 
  );
#ifndef sqlite3MemoryBarrier_IS_RELIABLE
  unixEnterMutex();               /* Also mutex, for redundancy */
  unixLeaveMutex();
#endif
}

/*
** Close a connection to shared-memory.  Delete the underlying 
** storage if deleteFlag is true.
**
** If there is no shared memory associated with the connection then this

Changes to src/os_win.c.

4170
4171
4172
4173
4174
4175
4176

4177
4178

4179
4180
4181
4182
4183
4184
4185
** any load or store begun after the barrier.
*/
static void winShmBarrier(
  sqlite3_file *fd          /* Database holding the shared memory */
){
  UNUSED_PARAMETER(fd);
  sqlite3MemoryBarrier();   /* compiler-defined memory barrier */

  winShmEnterMutex();       /* Also mutex, for redundancy */
  winShmLeaveMutex();

}

/*
** This function is called to obtain a pointer to region iRegion of the
** shared-memory associated with the database file fd. Shared-memory regions
** are numbered starting from zero. Each shared-memory region is szRegion
** bytes in size.







>


>







4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
** any load or store begun after the barrier.
*/
static void winShmBarrier(
  sqlite3_file *fd          /* Database holding the shared memory */
){
  UNUSED_PARAMETER(fd);
  sqlite3MemoryBarrier();   /* compiler-defined memory barrier */
#ifndef sqlite3MemoryBarrier_IS_RELIABLE
  winShmEnterMutex();       /* Also mutex, for redundancy */
  winShmLeaveMutex();
#endif
}

/*
** This function is called to obtain a pointer to region iRegion of the
** shared-memory associated with the database file fd. Shared-memory regions
** are numbered starting from zero. Each shared-memory region is szRegion
** bytes in size.