** WARNING: The "try_add_sql_pool" function assumes the hash lock is already ** held. */
| 159 | ** held. |
| 160 | */ |
| 161 | static int try_add_sql_pool(const char *zName, int nThreads, |
| 162 | struct thdpool *pool) |
| 163 | { |
| 164 | if (pool == NULL) return -1; /* cannot add, invalid pool */ |
| 165 | if (sqlengine_pool_hash == NULL) |
| 166 | { |
| 167 | sqlengine_pool_hash = hash_init_strptr(offsetof(pool_entry_t, zName)); |
| 168 | if (sqlengine_pool_hash == NULL) return -2; /* OOM (?) */ |
| 169 | } |
| 170 | const char *zEntryName = (zName != NULL) ? |
| 171 | thdpool_get_name(pool) : SQL_POOL_DEFLT_NAME; |
| 172 | pool_entry_t *entry = hash_find(sqlengine_pool_hash, &zEntryName); |
| 173 | if (entry != NULL) return -3; /* cannot add, already present */ |
| 174 | entry = calloc(1, sizeof(pool_entry_t)); |
| 175 | if (entry == NULL) return -4; /* OOM */ |
| 176 | entry->zName = zEntryName; |
| 177 | entry->nThreads = nThreads; /* as specified */ |
| 178 | entry->pPool = pool; |
| 179 | if (hash_add(sqlengine_pool_hash, entry) != 0) { |
| 180 | free(entry); |
| 181 | return -5; |
| 182 | } |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | int get_default_sql_pool_max_threads(void) |
| 187 | { |
no test coverage detected