[Spice-devel] [PATCH 7/8] Store surfaces_used in a bit-array

Yonit Halperin yhalperi at redhat.com
Sun Aug 22 06:02:05 PDT 2010


On 08/22/2010 03:56 PM, Yonit Halperin wrote:
> On 08/20/2010 09:54 PM, alexl at redhat.com wrote:
>> From: Alexander Larsson<alexl at redhat.com>
>>
>> This is smaller than a byte array, and allows us to skip full
>> blocks of 32 ids in one check.
>> ---
>
> Hi,
> why not use a linked list, for free surfaces, in a static
> UINT32[n_surfaces] array? Any reason besides space, which is 4k?
>
>>
>> static _inline void FreeSurface(PDev *pdev, UINT32 surface_id)
>> {
>> - pdev->Res.surfaces_used[surface_id] = 0;
>> + UINT32 i, bitmask;
>> +
>> + i = surface_id / 32;
>> + bitmask = (~0x80000000)>> (surface_id % 32);
>> +
>> + pdev->Res.surfaces_used[i]&= bitmask;
>> }
> shouldn't it be ~(0x80000000 << (surface_id % 32))?

I ment ~(0x80000000 >> (surface_id % 32))
>
>>
>>
>> static UINT32 GetFreeSurface(PDev *pdev)
>> {
>> - UINT32 x;
>> -
>> - //not effective, fix me
>> - for (x = 1; x< pdev->n_surfaces; ++x) {
>> - if (!pdev->Res.surfaces_used[x]) {
>> - pdev->Res.surfaces_used[x] = 1;
>> - return x;
>> + UINT32 start = 1;
>> + UINT32 bit;
>> + UINT32 i, end_i;
>> + UINT32 bitmask;
>> + UINT32 used_mask;
>> + UINT32 res = 0;
>> +
>> + i = start / 32;
>> + end_i = (pdev->n_surfaces + 31) / 32;
>> + bit = start % 32;
>> + bitmask = (0x80000000)>> (bit % 32);
>> +
>> + while (i< end_i) {
>> + used_mask = pdev->Res.surfaces_used[i];
>> + /* Avoid checks early if no unused */
>> + if (used_mask == 0xffffffff) {
> shouldn't it be used_mask != 0xffffffff?
>
>
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel



More information about the Spice-devel mailing list