From: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
To: xen-devel@lists.xensource.com
Subject: [PATCH 2/5] Add lock for xen-api class instances in XendAPIStore.py
Date: Fri, 13 Mar 2009 21:06:17 +0900 [thread overview]
Message-ID: <49BA4C39.4030403@ab.jp.nec.com> (raw)
In-Reply-To: <49BA4209.1020702@ab.jp.nec.com>
Add __classes_lock to protect __classes, since it can be modified by the udev
listener thread.
Signed-off-by: Yosuke Iwamatsu <y-iwamatsu@ab.jp.nec.com>
diff -r c30742011bb8 tools/python/xen/xend/XendAPIStore.py
--- a/tools/python/xen/xend/XendAPIStore.py Thu Mar 12 18:48:09 2009 +0000
+++ b/tools/python/xen/xend/XendAPIStore.py Fri Mar 13 16:36:52 2009 +0900
@@ -25,36 +25,59 @@
by type, to ensure safety
"""
+import threading
+
__classes = {}
+__classes_lock = threading.RLock()
def register(uuid, type, inst):
- __classes[(uuid, type)] = inst
- return inst
+ __classes_lock.acquire()
+ try:
+ __classes[(uuid, type)] = inst
+ return inst
+ finally:
+ __classes_lock.release()
def deregister(uuid, type):
- old = get(uuid, type)
- if old is not None:
- del __classes[(uuid, type)]
- return old
+ __classes_lock.acquire()
+ try:
+ old = get(uuid, type)
+ if old is not None:
+ del __classes[(uuid, type)]
+ return old
+ finally:
+ __classes_lock.release()
def get(uuid, type):
"""
Get the instances by uuid and type
"""
- return __classes.get((uuid, type), None)
+ __classes_lock.acquire()
+ try:
+ return __classes.get((uuid, type), None)
+ finally:
+ __classes_lock.release()
def get_all(all_type):
"""
Get all instances by type
"""
- return [inst
- for ((uuid, t), inst) in __classes.items()
- if t == all_type]
+ __classes_lock.acquire()
+ try:
+ return [inst
+ for ((uuid, t), inst) in __classes.items()
+ if t == all_type]
+ finally:
+ __classes_lock.release()
def get_all_uuid(all_type):
"""
Get all uuids by type
"""
- return [uuid
- for (uuid, t) in __classes.keys()
- if t == all_type]
+ __classes_lock.acquire()
+ try:
+ return [uuid
+ for (uuid, t) in __classes.keys()
+ if t == all_type]
+ finally:
+ __classes_lock.release()
next prev parent reply other threads:[~2009-03-13 12:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <49BA4209.1020702@ab.jp.nec.com>
2009-03-13 12:06 ` [PATCH 1/5] Implement DGRAM (connectionless) type socket listeners Yosuke Iwamatsu
2009-03-13 12:06 ` Yosuke Iwamatsu [this message]
2009-03-13 12:06 ` [PATCH 3/5] Add lock for lspci_info in pci.py Yosuke Iwamatsu
2009-03-13 12:06 ` [PATCH 4/5] Accept udev events and update physical resource information Yosuke Iwamatsu
2009-03-23 7:05 ` [PATCH 4/5] Accept udev events and update physicalresource information Masaki Kanno
2009-03-24 8:12 ` [PATCH] xend: save the state of PPCIs after hot-plug ([PATCH 4/5] Accept udev events and update physical resource information) Yosuke Iwamatsu
2009-03-25 9:24 ` Masaki Kanno
2009-03-13 12:06 ` [PATCH 5/5] Add udev rules to deliver hw events to xend Yosuke Iwamatsu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49BA4C39.4030403@ab.jp.nec.com \
--to=y-iwamatsu@ab.jp.nec.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.