Updated code based on review of ac308dcb2c34e081f9814ad40c0961a217c86fc4
Removed unnecessary spinlock and added more checks.
This commit is contained in:
@ -1495,15 +1495,6 @@ CONFIG_PARAMETER *p1, *p2;
|
||||
int
|
||||
config_threadcount()
|
||||
{
|
||||
spinlock_acquire(&gateway.lock);
|
||||
if(gateway.n_threads <= 0)
|
||||
{
|
||||
int nthr = get_processor_count();
|
||||
skygw_log_write(LE, "Warning: Invalid value for 'threads': %d. Using default "
|
||||
"number of %d threads.", gateway.n_threads, nthr);
|
||||
gateway.n_threads = nthr;
|
||||
}
|
||||
spinlock_release(&gateway.lock);
|
||||
return gateway.n_threads;
|
||||
}
|
||||
|
||||
@ -1564,7 +1555,16 @@ handle_global_item(const char *name, const char *value)
|
||||
int i;
|
||||
if (strcmp(name, "threads") == 0)
|
||||
{
|
||||
gateway.n_threads = atoi(value);
|
||||
int thrcount = atoi(value);
|
||||
if (thrcount > 0)
|
||||
{
|
||||
gateway.n_threads = thrcount;
|
||||
}
|
||||
else
|
||||
{
|
||||
skygw_log_write(LE, "Warning: Invalid value for 'threads': %d. Using default "
|
||||
"number of %d threads.", thrcount, gateway.n_threads);
|
||||
}
|
||||
}
|
||||
else if (strcmp(name, "non_blocking_polls") == 0)
|
||||
{
|
||||
@ -1667,7 +1667,6 @@ global_defaults()
|
||||
{
|
||||
uint8_t mac_addr[6]="";
|
||||
struct utsname uname_data;
|
||||
spinlock_init(&gateway.lock);
|
||||
gateway.n_threads = get_processor_count();
|
||||
gateway.n_nbpoll = DEFAULT_NBPOLLS;
|
||||
gateway.pollsleep = DEFAULT_POLLSLEEP;
|
||||
|
||||
@ -235,8 +235,14 @@ struct hostent *hp;
|
||||
long get_processor_count()
|
||||
{
|
||||
long processors = 1;
|
||||
#ifdef _SC_NPROCESSORS_CONF
|
||||
processors = sysconf(_SC_NPROCESSORS_CONF);
|
||||
#ifdef _SC_NPROCESSORS_ONLN
|
||||
if ((processors = sysconf(_SC_NPROCESSORS_ONLN)) <= 0)
|
||||
{
|
||||
skygw_log_write(LE, "Unable to establish the number of available cores. Defaulting to 4.");
|
||||
processors = 4;
|
||||
}
|
||||
#else
|
||||
#error _SC_NPROCESSORS_ONLN not available.
|
||||
#endif
|
||||
return processors;
|
||||
}
|
||||
@ -97,7 +97,6 @@ typedef struct config_context {
|
||||
* The gateway global configuration data
|
||||
*/
|
||||
typedef struct {
|
||||
SPINLOCK lock; /*< Lock used when accessing the global configuration */
|
||||
int n_threads; /**< Number of polling threads */
|
||||
char *version_string; /**< The version string of embedded database library */
|
||||
char release_string[_SYSNAME_STR_LENGTH]; /**< The release name string of the system */
|
||||
|
||||
Reference in New Issue
Block a user