Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
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
videolan
libva
Commits
88931373
Commit
88931373
authored
May 16, 2011
by
Xiang, Haihao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
i965_drv_video: thread safety for object allocation
Signed-off-by:
Xiang, Haihao
<
haihao.xiang@intel.com
>
parent
1587cb78
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
0 deletions
+21
-0
i965_drv_video/object_heap.c
i965_drv_video/object_heap.c
+18
-0
i965_drv_video/object_heap.h
i965_drv_video/object_heap.h
+3
-0
No files found.
i965_drv_video/object_heap.c
View file @
88931373
...
...
@@ -75,6 +75,7 @@ int object_heap_init( object_heap_p heap, int object_size, int id_offset)
heap
->
heap_increment
=
16
;
heap
->
heap_index
=
NULL
;
heap
->
next_free
=
LAST_FREE
;
_i965InitMutex
(
&
heap
->
mutex
);
return
object_heap_expand
(
heap
);
}
...
...
@@ -85,10 +86,13 @@ int object_heap_init( object_heap_p heap, int object_size, int id_offset)
int
object_heap_allocate
(
object_heap_p
heap
)
{
object_base_p
obj
;
_i965LockMutex
(
&
heap
->
mutex
);
if
(
LAST_FREE
==
heap
->
next_free
)
{
if
(
-
1
==
object_heap_expand
(
heap
)
)
{
_i965UnlockMutex
(
&
heap
->
mutex
);
return
-
1
;
/* Out of memory */
}
}
...
...
@@ -96,6 +100,8 @@ int object_heap_allocate( object_heap_p heap )
obj
=
(
object_base_p
)
(
heap
->
heap_index
+
heap
->
next_free
*
heap
->
object_size
);
heap
->
next_free
=
obj
->
next_free
;
_i965UnlockMutex
(
&
heap
->
mutex
);
obj
->
next_free
=
ALLOCATED
;
return
obj
->
id
;
}
...
...
@@ -107,12 +113,16 @@ int object_heap_allocate( object_heap_p heap )
object_base_p
object_heap_lookup
(
object_heap_p
heap
,
int
id
)
{
object_base_p
obj
;
_i965LockMutex
(
&
heap
->
mutex
);
if
(
(
id
<
heap
->
id_offset
)
||
(
id
>
(
heap
->
heap_size
+
heap
->
id_offset
))
)
{
_i965UnlockMutex
(
&
heap
->
mutex
);
return
NULL
;
}
id
&=
OBJECT_HEAP_ID_MASK
;
obj
=
(
object_base_p
)
(
heap
->
heap_index
+
id
*
heap
->
object_size
);
_i965UnlockMutex
(
&
heap
->
mutex
);
/* Check if the object has in fact been allocated */
if
(
obj
->
next_free
!=
ALLOCATED
)
...
...
@@ -140,16 +150,19 @@ object_base_p object_heap_next( object_heap_p heap, object_heap_iterator *iter )
{
object_base_p
obj
;
int
i
=
*
iter
+
1
;
_i965LockMutex
(
&
heap
->
mutex
);
while
(
i
<
heap
->
heap_size
)
{
obj
=
(
object_base_p
)
(
heap
->
heap_index
+
i
*
heap
->
object_size
);
if
(
obj
->
next_free
==
ALLOCATED
)
{
_i965UnlockMutex
(
&
heap
->
mutex
);
*
iter
=
i
;
return
obj
;
}
i
++
;
}
_i965UnlockMutex
(
&
heap
->
mutex
);
*
iter
=
i
;
return
NULL
;
}
...
...
@@ -167,8 +180,10 @@ void object_heap_free( object_heap_p heap, object_base_p obj )
/* Check if the object has in fact been allocated */
ASSERT
(
obj
->
next_free
==
ALLOCATED
);
_i965LockMutex
(
&
heap
->
mutex
);
obj
->
next_free
=
heap
->
next_free
;
heap
->
next_free
=
obj
->
id
&
OBJECT_HEAP_ID_MASK
;
_i965UnlockMutex
(
&
heap
->
mutex
);
}
}
...
...
@@ -179,6 +194,9 @@ void object_heap_destroy( object_heap_p heap )
{
object_base_p
obj
;
int
i
;
_i965DestroyMutex
(
&
heap
->
mutex
);
/* Check if heap is empty */
for
(
i
=
0
;
i
<
heap
->
heap_size
;
i
++
)
{
...
...
i965_drv_video/object_heap.h
View file @
88931373
...
...
@@ -25,6 +25,8 @@
#ifndef _OBJECT_HEAP_H_
#define _OBJECT_HEAP_H_
#include "i965_mutext.h"
#define OBJECT_HEAP_OFFSET_MASK 0x7F000000
#define OBJECT_HEAP_ID_MASK 0x00FFFFFF
...
...
@@ -43,6 +45,7 @@ struct object_heap {
int
next_free
;
int
heap_size
;
int
heap_increment
;
_I965Mutex
mutex
;
};
typedef
int
object_heap_iterator
;
...
...
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