Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
djinni
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
djinni
Commits
2aa776b9
Commit
2aa776b9
authored
May 18, 2015
by
Jacob Potter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Don't use weakToStrongObjectsMapTable in ObjcWrapperCache
parent
9996b441
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
15 deletions
+6
-15
support-lib/objc/DJIObjcWrapperCache+Private.h
support-lib/objc/DJIObjcWrapperCache+Private.h
+6
-15
No files found.
support-lib/objc/DJIObjcWrapperCache+Private.h
View file @
2aa776b9
...
@@ -16,7 +16,6 @@
...
@@ -16,7 +16,6 @@
// This header can only be imported to Objective-C++ source code!
// This header can only be imported to Objective-C++ source code!
#import "DJIWeakPtrWrapper+Private.h"
#import <Foundation/Foundation.h>
#import <Foundation/Foundation.h>
#include <memory>
#include <memory>
#include <mutex>
#include <mutex>
...
@@ -37,9 +36,9 @@ public:
...
@@ -37,9 +36,9 @@ public:
std
::
shared_ptr
<
T
>
get
(
id
objcRef
)
{
std
::
shared_ptr
<
T
>
get
(
id
objcRef
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
m_mutex
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
m_mutex
);
std
::
shared_ptr
<
T
>
ret
;
std
::
shared_ptr
<
T
>
ret
;
DBWeakPtrWrapper
*
wrapper
=
[
m_mapping
objectForKey
:
objcRef
]
;
auto
it
=
m_mapping
.
find
((
__bridge
void
*
)
objcRef
)
;
if
(
wrapper
!=
nil
)
{
if
(
it
!=
m_mapping
.
end
()
)
{
ret
=
std
::
static_pointer_cast
<
T
>
(
wrapper
.
ptr
.
lock
());
ret
=
std
::
static_pointer_cast
<
T
>
(
it
->
second
.
lock
());
if
(
ret
==
nullptr
)
{
if
(
ret
==
nullptr
)
{
ret
=
new_wrapper
(
objcRef
);
ret
=
new_wrapper
(
objcRef
);
}
}
...
@@ -51,10 +50,7 @@ public:
...
@@ -51,10 +50,7 @@ public:
void
remove
(
id
objcRef
)
{
void
remove
(
id
objcRef
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
m_mutex
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
m_mutex
);
DBWeakPtrWrapper
*
wrapper
=
[
m_mapping
objectForKey
:
objcRef
];
m_mapping
.
erase
((
__bridge
void
*
)
objcRef
);
if
(
wrapper
.
ptr
.
expired
())
{
[
m_mapping
removeObjectForKey
:
objcRef
];
}
}
}
class
Handle
{
class
Handle
{
...
@@ -74,18 +70,13 @@ public:
...
@@ -74,18 +70,13 @@ public:
private:
private:
NSMapTable
*
m_mapping
;
std
::
unordered_map
<
void
*
,
std
::
weak_ptr
<
void
>>
m_mapping
;
std
::
mutex
m_mutex
;
std
::
mutex
m_mutex
;
DbxObjcWrapperCache
()
{
m_mapping
=
[
NSMapTable
weakToStrongObjectsMapTable
];
}
std
::
shared_ptr
<
T
>
new_wrapper
(
id
objcRef
)
{
std
::
shared_ptr
<
T
>
new_wrapper
(
id
objcRef
)
{
std
::
shared_ptr
<
T
>
ret
=
std
::
make_shared
<
T
>
(
objcRef
);
std
::
shared_ptr
<
T
>
ret
=
std
::
make_shared
<
T
>
(
objcRef
);
std
::
weak_ptr
<
void
>
ptr
(
std
::
static_pointer_cast
<
void
>
(
ret
));
std
::
weak_ptr
<
void
>
ptr
(
std
::
static_pointer_cast
<
void
>
(
ret
));
DBWeakPtrWrapper
*
wrapper
=
[[
DBWeakPtrWrapper
alloc
]
initWithWeakPtr
:
ptr
];
m_mapping
[(
__bridge
void
*
)
objcRef
]
=
ptr
;
[
m_mapping
setObject
:
wrapper
forKey
:
objcRef
];
return
ret
;
return
ret
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment