diff options
author | nicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-10-15 22:27:39 +0000 |
---|---|---|
committer | nicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4> | 2010-10-15 22:27:39 +0000 |
commit | cd9fd8f49ed8d1933887d048b692de11a2247e88 (patch) | |
tree | 4a6954b1f7b91675bedaa8e8b7d3351ee0f9d7d7 /libobjc/methods.c | |
parent | 4730466b5737baca4efd606025cb52b019fd6613 (diff) | |
download | gcc-cd9fd8f49ed8d1933887d048b692de11a2247e88.tar.gz |
In libobjc/:
2010-10-15 Nicola Pero <nicola.pero@meta-innovation.com>
* objc-private/runtime.h (__objc_update_classes_with_methods): New.
* class.c (__objc_update_classes_with_methods): New.
(objc_getClassList): Do not lock the class lock.
* methods.c (method_exchangeImplementations): New.
(method_setImplementation): New.
* objc/runtime.h (method_setImplementation): New.
(method_exchangeImplementations): New.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@165525 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libobjc/methods.c')
-rw-r--r-- | libobjc/methods.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/libobjc/methods.c b/libobjc/methods.c index 65939a6d5cd..b4faee533c2 100644 --- a/libobjc/methods.c +++ b/libobjc/methods.c @@ -124,3 +124,54 @@ class_copyMethodList (Class class_, unsigned int *numberOfReturnedMethods) return returnValue; } + +IMP +method_setImplementation (struct objc_method * method, IMP implementation) +{ + IMP old_implementation; + + if (method == NULL || implementation == NULL) + return NULL; + + /* We lock the runtime mutex so that concurrent calls to change the + same method won't conflict with each other. */ + objc_mutex_lock (__objc_runtime_mutex); + + old_implementation = method->method_imp; + method->method_imp = implementation; + + /* That was easy :-). But now we need to find all classes that use + this method, and update the IMP in the dispatch tables. */ + __objc_update_classes_with_methods (method, NULL); + + objc_mutex_unlock (__objc_runtime_mutex); + + return old_implementation; +} + +void +method_exchangeImplementations (struct objc_method * method_a, struct objc_method * method_b) +{ + IMP old_implementation_a; + IMP old_implementation_b; + + if (method_a == NULL || method_b == NULL) + return; + + /* We lock the runtime mutex so that concurrent calls to exchange + similar methods won't conflict with each other. Each of them + should be atomic. */ + objc_mutex_lock (__objc_runtime_mutex); + + old_implementation_a = method_a->method_imp; + old_implementation_b = method_b->method_imp; + + method_a->method_imp = old_implementation_b; + method_b->method_imp = old_implementation_a; + + /* That was easy :-). But now we need to find all classes that use + these methods, and update the IMP in the dispatch tables. */ + __objc_update_classes_with_methods (method_a, method_b); + + objc_mutex_unlock (__objc_runtime_mutex); +} |