/ Check-in [055b36f1]
Login

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

Overview
Comment:New simplified memory initialization for MacOS.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 055b36f1c1593bb123f7319a07c476143d71af052b5b8d34afcd0d500f197882
User & Date: drh 2017-03-21 20:17:24
Context
2017-03-22
21:24
Initial implementation of the json_mergepatch(A,B) SQL function. check-in: a2674440 user: drh tags: json_mergepatch
12:51
Fix harmless compiler warnings in the shell. check-in: a7868297 user: drh tags: trunk
2017-03-21
20:17
New simplified memory initialization for MacOS. check-in: 055b36f1 user: drh tags: trunk
18:56
Fix an incorrect assert in the ANALYZE logic for STAT4 on WITHOUT ROWID tables. check-in: ad741976 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/mem1.c.

234
235
236
237
238
239
240


241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
}

/*
** Initialize this module.
*/
static int sqlite3MemInit(void *NotUsed){
#if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)


  if( _sqliteZone_ ){
    return SQLITE_OK;
  }
#ifndef SQLITE_MIGHT_BE_SINGLE_CORE
  /* If not compiled with the SQLITE_MIGHT_BE_SINGLE_CORE flag, assume
  ** that multiple cores are always available.  This is the default case.
  */
  _sqliteZone_ = malloc_default_zone();
#else
  /* With the SQLITE_MIGHT_BE_SINGLE_CORE compile-time option, check the
  ** number of cores.  Different malloc() strategies are used for single-core and
  ** multi-core machines.
  */
  {
    int cpuCount;
    size_t len;
    len = sizeof(cpuCount);
    /* One usually wants to use hw.acctivecpu for MT decisions, but not here */
    sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0);
    if( cpuCount>1 ){
      /* defer MT decisions to system malloc */
      _sqliteZone_ = malloc_default_zone();
    }else{
      /* only 1 core, use our own zone to contention over global locks, 
      ** e.g. we have our own dedicated locks */
      bool success;
      malloc_zone_t* newzone = malloc_create_zone(4096, 0);
      malloc_set_zone_name(newzone, "Sqlite_Heap");
      do{
        success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, 
                                   (void * volatile *)&_sqliteZone_);
      }while(!_sqliteZone_);
      if( !success ){
        /* somebody registered a zone first */
        malloc_destroy_zone(newzone);
      }
    }
  }
#endif /* SQLITE_MIGHT_BE_SINGLE_CORE */
#endif /*  defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) */
  UNUSED_PARAMETER(NotUsed);
  return SQLITE_OK;
}

/*
** Deinitialize this module.







>
>



<
<
<
<
<
<
<
<
<
<
<
<
<
|
|
|
|
|
|
|
|
|
<
|
|
<
<
<
<
<
<
<
|
<
<
<







234
235
236
237
238
239
240
241
242
243
244
245













246
247
248
249
250
251
252
253
254

255
256







257



258
259
260
261
262
263
264
}

/*
** Initialize this module.
*/
static int sqlite3MemInit(void *NotUsed){
#if defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC)
  int cpuCount;
  size_t len;
  if( _sqliteZone_ ){
    return SQLITE_OK;
  }













  len = sizeof(cpuCount);
  /* One usually wants to use hw.acctivecpu for MT decisions, but not here */
  sysctlbyname("hw.ncpu", &cpuCount, &len, NULL, 0);
  if( cpuCount>1 ){
    /* defer MT decisions to system malloc */
    _sqliteZone_ = malloc_default_zone();
  }else{
    /* only 1 core, use our own zone to contention over global locks, 
    ** e.g. we have our own dedicated locks */

    _sqliteZone_ = malloc_create_zone(4096, 0);
    malloc_set_zone_name(_sqliteZone_, "Sqlite_Heap");







  }



#endif /*  defined(__APPLE__) && !defined(SQLITE_WITHOUT_ZONEMALLOC) */
  UNUSED_PARAMETER(NotUsed);
  return SQLITE_OK;
}

/*
** Deinitialize this module.