library: refine support for multiple concurrent access
Our new library's now well protected against potential problems which arise when a multi-threaded application opens more than one context within the same API at the same time. However, with a single-threaded application designed along those same lines, some problems remain. So, to avoid potential corruption of some data (which was classified as local 'static __thread') from those single-threaded designs, we'll move several variables to the info structure itself and remove the '__thread' qualifier. Now they're protected against both designs. [ we'll not be protected against some multi-threaded ] [ application that shares a single context yet calls ] [ that interface from separate threads. this is just ] [ bad application design & no different than sharing ] [ other modifiable global data between such threads! ] Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
@@ -135,6 +135,7 @@ struct meminfo_info {
|
||||
struct stacks_extent *extents;
|
||||
struct hsearch_data hashtab;
|
||||
struct meminfo_result get_this;
|
||||
time_t sav_secs;
|
||||
};
|
||||
|
||||
|
||||
@@ -882,7 +883,6 @@ PROCPS_EXPORT struct meminfo_result *procps_meminfo_get (
|
||||
struct meminfo_info *info,
|
||||
enum meminfo_item item)
|
||||
{
|
||||
static __thread time_t sav_secs;
|
||||
time_t cur_secs;
|
||||
|
||||
errno = EINVAL;
|
||||
@@ -895,10 +895,10 @@ PROCPS_EXPORT struct meminfo_result *procps_meminfo_get (
|
||||
/* we will NOT read the meminfo file with every call - rather, we'll offer
|
||||
a granularity of 1 second between reads ... */
|
||||
cur_secs = time(NULL);
|
||||
if (1 <= cur_secs - sav_secs) {
|
||||
if (1 <= cur_secs - info->sav_secs) {
|
||||
if (meminfo_read_failed(info))
|
||||
return NULL;
|
||||
sav_secs = cur_secs;
|
||||
info->sav_secs = cur_secs;
|
||||
}
|
||||
|
||||
info->get_this.item = item;
|
||||
|
||||
Reference in New Issue
Block a user