mirror of https://github.com/ecmwf/eccodes.git
Context shared resource needs mutex
This commit is contained in:
parent
e7e4a35b18
commit
68dd0b3b87
|
@ -133,14 +133,13 @@ static void init_class(grib_accessor_class* c)
|
|||
|
||||
static void init(grib_accessor* a,const long l, grib_arguments* c)
|
||||
{
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
a->length=0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
a->length=0;
|
||||
}
|
||||
|
||||
static int unpack_long(grib_accessor* a, long* val, size_t *len)
|
||||
static int unpack_long(grib_accessor* a, long* val, size_t *len)
|
||||
{
|
||||
*val = a->context->handle_file_count;
|
||||
*len =1;
|
||||
return 0;
|
||||
*val = grib_context_get_handle_file_count(a->context);
|
||||
*len =1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -135,14 +135,13 @@ static void init_class(grib_accessor_class* c)
|
|||
|
||||
static void init(grib_accessor* a,const long l, grib_arguments* c)
|
||||
{
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
a->length=0;
|
||||
a->flags |= GRIB_ACCESSOR_FLAG_READ_ONLY;
|
||||
a->length=0;
|
||||
}
|
||||
|
||||
static int unpack_long(grib_accessor* a, long* val, size_t *len)
|
||||
{
|
||||
*val = a->context->handle_total_count;
|
||||
*len =1;
|
||||
return 0;
|
||||
*val = grib_context_get_handle_total_count(a->context);
|
||||
*len =1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -994,6 +994,8 @@ void grib_context_set_buffer_memory_proc(grib_context *c, grib_malloc_proc m, gr
|
|||
void grib_context_set_data_accessing_proc(grib_context *c, grib_data_read_proc read, grib_data_write_proc write, grib_data_tell_proc tell);
|
||||
void grib_context_log(const grib_context *c, int level, const char *fmt, ...);
|
||||
void grib_context_print(const grib_context *c, void *descriptor, const char *fmt, ...);
|
||||
int grib_context_get_handle_file_count(grib_context *c);
|
||||
int grib_context_get_handle_total_count(grib_context *c);
|
||||
void grib_context_set_handle_file_count(grib_context *c, int new_count);
|
||||
void grib_context_set_handle_total_count(grib_context *c, int new_count);
|
||||
void grib_context_increment_handle_file_count(grib_context *c);
|
||||
|
|
|
@ -946,6 +946,27 @@ void grib_context_print(const grib_context *c, void* descriptor,const char* fmt,
|
|||
c->print(c,descriptor,msg);
|
||||
}
|
||||
|
||||
int grib_context_get_handle_file_count(grib_context *c)
|
||||
{
|
||||
int r = 0;
|
||||
if (!c) c=grib_context_get_default();
|
||||
GRIB_MUTEX_INIT_ONCE(&once,&init);
|
||||
GRIB_MUTEX_LOCK(&mutex_c);
|
||||
r = c->handle_file_count;
|
||||
GRIB_MUTEX_UNLOCK(&mutex_c);
|
||||
return r;
|
||||
}
|
||||
int grib_context_get_handle_total_count(grib_context *c)
|
||||
{
|
||||
int r = 0;
|
||||
if (!c) c=grib_context_get_default();
|
||||
GRIB_MUTEX_INIT_ONCE(&once,&init);
|
||||
GRIB_MUTEX_LOCK(&mutex_c);
|
||||
r=c->handle_total_count;
|
||||
GRIB_MUTEX_UNLOCK(&mutex_c);
|
||||
return r;
|
||||
}
|
||||
|
||||
void grib_context_set_handle_file_count(grib_context *c, int new_count)
|
||||
{
|
||||
if (!c) c=grib_context_get_default();
|
||||
|
@ -954,7 +975,6 @@ void grib_context_set_handle_file_count(grib_context *c, int new_count)
|
|||
c->handle_file_count = new_count;
|
||||
GRIB_MUTEX_UNLOCK(&mutex_c);
|
||||
}
|
||||
|
||||
void grib_context_set_handle_total_count(grib_context *c, int new_count)
|
||||
{
|
||||
if (!c) c=grib_context_get_default();
|
||||
|
@ -972,7 +992,6 @@ void grib_context_increment_handle_file_count(grib_context *c)
|
|||
c->handle_file_count++;
|
||||
GRIB_MUTEX_UNLOCK(&mutex_c);
|
||||
}
|
||||
|
||||
void grib_context_increment_handle_total_count(grib_context *c)
|
||||
{
|
||||
if (!c) c=grib_context_get_default();
|
||||
|
|
Loading…
Reference in New Issue