objc: add comment about Objective-C global lock
objc.RegisterName grabs the global Objective-C lock. This commit adds a commit to Send, SendSuper and RegisterName about this lock. Closes #86
- commit
- 6d5fb775f30b3ac81494cfdefb424252b546d0a2
- author
- TotallyGamerJet · · 2023-01-07 17:37 UTC
- committer
- GitHub · · 2023-01-07 17:37 UTC
- parent
- a7c4d8f
- signature
- GPG Unverified
4AEE18F83AFDEB23The key is unknown
1 file · +8 -3
M objc/objc_runtime_darwin.go +8 -3
| @@ -63,7 +63,9 @@ func (id ID) Class() Class { | |||
| 63 | 63 | return object_getClass(id) | |
| 64 | 64 | } | |
| 65 | 65 | ||
| 66 | - | // Send is a convenience method for sending messages to objects. | |
| 66 | + | // Send is a convenience method for sending messages to objects. This function takes a SEL | |
| 67 | + | // instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result | |
| 68 | + | // of RegisterName. | |
| 67 | 69 | func (id ID) Send(sel SEL, args ...interface{}) ID { | |
| 68 | 70 | return objc_msgSend(id, sel, args...) | |
| 69 | 71 | } | |
| @@ -76,7 +78,9 @@ type objc_super struct { | |||
| 76 | 78 | superClass Class | |
| 77 | 79 | } | |
| 78 | 80 | ||
| 79 | - | // SendSuper is a convenience method for sending message to object's super | |
| 81 | + | // SendSuper is a convenience method for sending message to object's super. This function takes a SEL | |
| 82 | + | // instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result | |
| 83 | + | // of RegisterName. | |
| 80 | 84 | func (id ID) SendSuper(sel SEL, args ...interface{}) ID { | |
| 81 | 85 | var super = &objc_super{ | |
| 82 | 86 | receiver: id, | |
| @@ -89,7 +93,8 @@ func (id ID) SendSuper(sel SEL, args ...interface{}) ID { | |||
| 89 | 93 | type SEL uintptr | |
| 90 | 94 | ||
| 91 | 95 | // RegisterName registers a method with the Objective-C runtime system, maps the method name to a selector, | |
| 92 | - | // and returns the selector value. | |
| 96 | + | // and returns the selector value. This function grabs the global Objective-c lock. It is best the cache the | |
| 97 | + | // result of this function. | |
| 93 | 98 | func RegisterName(name string) SEL { | |
| 94 | 99 | return sel_registerName(name) | |
| 95 | 100 | } | |
| @@ -63,7 +63,9 @@ func (id ID) Class() Class { | |||||
| 63 | return object_getClass(id) | 63 | return object_getClass(id) | ||
| 64 | } | 64 | } | ||
| 65 | 65 | ||||
| 66 | - | // Send is a convenience method for sending messages to objects. | 66 | + | // Send is a convenience method for sending messages to objects. This function takes a SEL |
| 67 | + | // instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result | |||
| 68 | + | // of RegisterName. | |||
| 67 | func (id ID) Send(sel SEL, args ...interface{}) ID { | 69 | func (id ID) Send(sel SEL, args ...interface{}) ID { | ||
| 68 | return objc_msgSend(id, sel, args...) | 70 | return objc_msgSend(id, sel, args...) | ||
| 69 | } | 71 | } | ||
| @@ -76,7 +78,9 @@ type objc_super struct { | |||||
| 76 | superClass Class | 78 | superClass Class | ||
| 77 | } | 79 | } | ||
| 78 | 80 | ||||
| 79 | - | // SendSuper is a convenience method for sending message to object's super | 81 | + | // SendSuper is a convenience method for sending message to object's super. This function takes a SEL |
| 82 | + | // instead of a string since RegisterName grabs the global Objective-C lock. It is best to cache the result | |||
| 83 | + | // of RegisterName. | |||
| 80 | func (id ID) SendSuper(sel SEL, args ...interface{}) ID { | 84 | func (id ID) SendSuper(sel SEL, args ...interface{}) ID { | ||
| 81 | var super = &objc_super{ | 85 | var super = &objc_super{ | ||
| 82 | receiver: id, | 86 | receiver: id, | ||
| @@ -89,7 +93,8 @@ func (id ID) SendSuper(sel SEL, args ...interface{}) ID { | |||||
| 89 | type SEL uintptr | 93 | type SEL uintptr | ||
| 90 | 94 | ||||
| 91 | // RegisterName registers a method with the Objective-C runtime system, maps the method name to a selector, | 95 | // RegisterName registers a method with the Objective-C runtime system, maps the method name to a selector, | ||
| 92 | - | // and returns the selector value. | 96 | + | // and returns the selector value. This function grabs the global Objective-c lock. It is best the cache the |
| 97 | + | // result of this function. | |||
| 93 | func RegisterName(name string) SEL { | 98 | func RegisterName(name string) SEL { | ||
| 94 | return sel_registerName(name) | 99 | return sel_registerName(name) | ||
| 95 | } | 100 | } | ||