/ Check-in [3aa8befe]
Login

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

Overview
Comment:Windows implementation of the thread-specific data interface. (CVS 2864)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3aa8befedf4534cd100a7309997a4ad2ba08af20
User & Date: drh 2006-01-06 00:36:01
Context
2006-01-06
01:42
Formatting changes in btree.c. (CVS 2865) check-in: f1922da2 user: drh tags: trunk
00:36
Windows implementation of the thread-specific data interface. (CVS 2864) check-in: 3aa8befe user: drh tags: trunk
2006-01-05
23:42
Disable the update hook for the truncation optimization used by DELETE. (CVS 2863) check-in: 448b3b9d user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

  1659   1659           return 0;
  1660   1660         }
  1661   1661         keyInit = 1;
  1662   1662       }
  1663   1663       sqlite3Os.xLeaveMutex();
  1664   1664     }
  1665   1665   
  1666         -  pTsd = (SqliteTsd *)pthread_getspecific(key);
         1666  +  pTsd = pthread_getspecific(key);
  1667   1667     if( !pTsd ){
  1668         -    pTsd = sqlite3Os.xMalloc(sizeof(SqliteTsd));
         1668  +    pTsd = sqlite3Os.xMalloc(nByte);
  1669   1669       if( pTsd ){
  1670         -      memset(pTsd, 0, sizeof(SqliteTsd));
         1670  +      memset(pTsd, 0, nByte);
  1671   1671         pthread_setspecific(key, pTsd);
  1672   1672       }
  1673   1673     }
  1674   1674     return pTsd;
  1675   1675   #else
  1676         -  static char tsd[sizeof(SqliteTsd)];
  1677         -  static int isInit = 0;
  1678         -  assert( nByte==sizeof(SqliteTsd) );
  1679         -  if( !isInit ){
  1680         -    memset(tsd, 0, sizeof(SqliteTsd));
  1681         -    isInit = 1;
         1676  +  static void *pTsd = 0;
         1677  +  if( !pTsd ){
         1678  +    pTsd = sqlite3Os.xMalloc(nByte);
         1679  +    if( pTsd ){
         1680  +      memset(pTsd, 0, nByte);
         1681  +    }
  1682   1682     }
  1683         -  return (void *)tsd;
         1683  +  return pTsd;
  1684   1684   #endif
  1685   1685   }
  1686   1686   
  1687   1687   /*
  1688   1688   ** The following variable, if set to a non-zero value, becomes the result
  1689   1689   ** returned from sqlite3Os.xCurrentTime().  This is used for testing.
  1690   1690   */

Changes to src/os_win.c.

  1027   1027     if( sqlite3_current_time ){
  1028   1028       *prNow = sqlite3_current_time/86400.0 + 2440587.5;
  1029   1029     }
  1030   1030   #endif
  1031   1031     return 0;
  1032   1032   }
  1033   1033   
  1034         -
  1035         -/*
  1036         -** Todo: This is a place-holder only
         1034  +/* 
         1035  +** The first time this function is called from a specific thread, nByte 
         1036  +** bytes of data area are allocated and zeroed. A pointer to the new 
         1037  +** allocation is returned to the caller. 
         1038  +**
         1039  +** Each subsequent call to this function from the thread returns the same
         1040  +** pointer. The argument is ignored in this case.
  1037   1041   */
  1038   1042   static void *winThreadSpecificData(int nByte){
  1039         -  static char tsd[sizeof(SqliteTsd)];
  1040         -  static isInit = 0;
  1041         -  assert( nByte==sizeof(SqliteTsd) );
  1042         -  if( !isInit ){
  1043         -    memset(tsd, 0, sizeof(SqliteTsd));
  1044         -    isInit = 1;
         1043  +  static void *pTsd = 0;
         1044  +  static int key;
         1045  +  static int keyInit = 0;
         1046  +
         1047  +  if( !keyInit ){
         1048  +    sqlite3Os.xEnterMutex();
         1049  +    if( !keyInit ){
         1050  +      key = TlsAlloc();
         1051  +      if( key==0xffffffff ){
         1052  +        sqlite3Os.xLeaveMutex();
         1053  +        return 0;
         1054  +      }
         1055  +      keyInit = 1;
         1056  +    }
         1057  +    sqlite3Os.xLeaveMutex();
         1058  +  }
         1059  +  pTsd = TlsGetValue(key);
         1060  +  if( !pTsd ){
         1061  +    pTsd = sqlite3Os.xMalloc(nByte);
         1062  +    if( pTsd ){
         1063  +      memset(pTsd, 0, nByte);
         1064  +      TlsSetValue(key, pTsd);
         1065  +    }
  1045   1066     }
  1046         -  return (void *)tsd;
         1067  +  return pTsd;
  1047   1068   }
  1048   1069   
  1049   1070   /* Macro used to comment out routines that do not exists when there is
  1050   1071   ** no disk I/O
  1051   1072   */
  1052   1073   #ifdef SQLITE_OMIT_DISKIO
  1053   1074   # define IF_DISKIO(X)  0