Page MenuHomeFreeBSD

D61215.1794752959.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D61215.1794752959.diff

diff --git a/lib/libthr/thread/thr_private.h b/lib/libthr/thread/thr_private.h
--- a/lib/libthr/thread/thr_private.h
+++ b/lib/libthr/thread/thr_private.h
@@ -519,6 +519,7 @@
void *pshared_key;
void *pshared_val;
unsigned long pshared_gen;
+ unsigned long pshared_seq;
/*
* Current locks bitmap for rtld. */
diff --git a/lib/libthr/thread/thr_pshared.c b/lib/libthr/thread/thr_pshared.c
--- a/lib/libthr/thread/thr_pshared.c
+++ b/lib/libthr/thread/thr_pshared.c
@@ -107,19 +107,35 @@
static void *
pshared_cache_lookup(struct pthread *curthread, void *key)
{
+ unsigned long seq;
+ void *res;
+
+ seq = curthread->pshared_seq;
+ __compiler_membar();
if (curthread->pshared_key == key &&
curthread->pshared_gen == atomic_load_long(&pshared_gen.val))
- return (curthread->pshared_val);
- return (NULL);
+ res = curthread->pshared_val;
+ else
+ res = NULL;
+ __compiler_membar();
+ if (curthread->pshared_seq != seq)
+ res = NULL;
+ return (res);
}
static void
pshared_cache_insert(struct pthread *curthread, void *key, void *val,
unsigned long gen)
{
+ // Hold the pshared_lock
+ THR_ASSERT_LOCKLEVEL(curthread);
+ THR_ASSERT((pshared_lock.rw_state &
+ (URWLOCK_WRITE_OWNER | URWLOCK_MAX_READERS)) != 0,
+ "pshared_cache_insert: pshared_lock not held");
curthread->pshared_key = key;
curthread->pshared_val = val;
curthread->pshared_gen = gen;
+ curthread->pshared_seq++;
}
/*
@@ -276,7 +292,6 @@
{
struct pthread *curthread;
void *res;
- unsigned long gen;
int fd, ins_done;
curthread = _get_curthread();
@@ -288,13 +303,13 @@
if (res != NULL)
return (res);
pshared_rlock(curthread);
- gen = pshared_gen.val;
res = pshared_lookup(key);
+ if (res != NULL)
+ pshared_cache_insert(curthread, key, res,
+ pshared_gen.val);
pshared_unlock(curthread);
- if (res != NULL) {
- pshared_cache_insert(curthread, key, res, gen);
+ if (res != NULL)
return (res);
- }
}
fd = _umtx_op(NULL, UMTX_OP_SHM, doalloc ? UMTX_SHM_CREAT :
UMTX_SHM_LOOKUP, key, NULL);
@@ -305,14 +320,13 @@
if (res == MAP_FAILED)
return (NULL);
pshared_wlock(curthread);
- gen = pshared_gen.val;
ins_done = pshared_insert(key, &res);
+ if (ins_done)
+ pshared_cache_insert(curthread, key, res, pshared_gen.val);
pshared_unlock(curthread);
if (!ins_done) {
pshared_clean(key, res);
res = NULL;
- } else {
- pshared_cache_insert(curthread, key, res, gen);
}
return (res);
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 15, 2:29 PM (6 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41743986
Default Alt Text
D61215.1794752959.diff (2 KB)

Event Timeline