[pulseaudio-commits] r1459 - in /trunk/src: pulsecore/atomic.h pulsecore/cli-command.c pulsecore/memblock.c pulsecore/memblock.h pulsecore/protocol-native.c tests/memblock-test.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Sun May 27 13:38:15 PDT 2007


Author: lennart
Date: Sun May 27 22:38:14 2007
New Revision: 1459

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1459&root=3Dpulseaudio&vi=
ew=3Drev
Log:
Replace AO_xxx usage with pa_atomic_xxx and friends wherever it makes sense

Modified:
    trunk/src/pulsecore/atomic.h
    trunk/src/pulsecore/cli-command.c
    trunk/src/pulsecore/memblock.c
    trunk/src/pulsecore/memblock.h
    trunk/src/pulsecore/protocol-native.c
    trunk/src/tests/memblock-test.c

Modified: trunk/src/pulsecore/atomic.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/atomic.h?re=
v=3D1459&root=3Dpulseaudio&r1=3D1458&r2=3D1459&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/pulsecore/atomic.h (original)
+++ trunk/src/pulsecore/atomic.h Sun May 27 22:38:14 2007
@@ -53,6 +53,10 @@
     return AO_fetch_and_add_full(&a->value, (AO_t) i);
 }
 =

+static inline int pa_atomic_sub(pa_atomic_int_t *a, int i) {
+    return AO_fetch_and_add_full(&a->value, (AO_t) -i);
+}
+
 static inline int pa_atomic_inc(pa_atomic_int_t *a) {
     return AO_fetch_and_add1_full(&a->value);
 }

Modified: trunk/src/pulsecore/cli-command.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/cli-command=
.c?rev=3D1459&root=3Dpulseaudio&r1=3D1458&r2=3D1459&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/pulsecore/cli-command.c (original)
+++ trunk/src/pulsecore/cli-command.c Sun May 27 22:38:14 2007
@@ -273,20 +273,20 @@
     stat =3D pa_mempool_get_stat(c->mempool);
 =

     pa_strbuf_printf(buf, "Memory blocks currently allocated: %u, size: %s=
.\n",
-                     (unsigned) AO_load_acquire_read((AO_t*) &stat->n_allo=
cated),
-                     pa_bytes_snprint(s, sizeof(s), (size_t) AO_load_acqui=
re_read((AO_t*) &stat->allocated_size)));
+                     (unsigned) pa_atomic_load(&stat->n_allocated),
+                     pa_bytes_snprint(s, sizeof(s), (size_t) pa_atomic_loa=
d(&stat->allocated_size)));
 =

     pa_strbuf_printf(buf, "Memory blocks allocated during the whole lifeti=
me: %u, size: %s.\n",
-                     (unsigned) AO_load_acquire_read((AO_t*) &stat->n_accu=
mulated),
-                     pa_bytes_snprint(s, sizeof(s), (size_t) AO_load_acqui=
re_read((AO_t*) &stat->accumulated_size)));
+                     (unsigned) pa_atomic_load(&stat->n_accumulated),
+                     pa_bytes_snprint(s, sizeof(s), (size_t) pa_atomic_loa=
d(&stat->accumulated_size)));
 =

     pa_strbuf_printf(buf, "Memory blocks imported from other processes: %u=
, size: %s.\n",
-                     (unsigned) AO_load_acquire_read((AO_t*) &stat->n_impo=
rted),
-                     pa_bytes_snprint(s, sizeof(s), (size_t) AO_load_acqui=
re_read((AO_t*) &stat->imported_size)));
+                     (unsigned) pa_atomic_load(&stat->n_imported),
+                     pa_bytes_snprint(s, sizeof(s), (size_t) pa_atomic_loa=
d(&stat->imported_size)));
 =

     pa_strbuf_printf(buf, "Memory blocks exported to other processes: %u, =
size: %s.\n",
-                     (unsigned) AO_load_acquire_read((AO_t*) &stat->n_expo=
rted),
-                     pa_bytes_snprint(s, sizeof(s), (size_t) AO_load_acqui=
re_read((AO_t*) &stat->exported_size)));
+                     (unsigned) pa_atomic_load(&stat->n_exported),
+                     pa_bytes_snprint(s, sizeof(s), (size_t) pa_atomic_loa=
d(&stat->exported_size)));
 =

     pa_strbuf_printf(buf, "Total sample cache size: %s.\n",
                      pa_bytes_snprint(s, sizeof(s), pa_scache_total_size(c=
)));
@@ -305,8 +305,8 @@
         pa_strbuf_printf(buf,
                          "Memory blocks of type %s: %u allocated/%u accumu=
lated.\n",
                          type_table[k],
-                         (unsigned) AO_load_acquire_read(&stat->n_allocate=
d_by_type[k]),
-                         (unsigned) AO_load_acquire_read(&stat->n_accumula=
ted_by_type[k]));
+                         (unsigned) pa_atomic_load(&stat->n_allocated_by_t=
ype[k]),
+                         (unsigned) pa_atomic_load(&stat->n_accumulated_by=
_type[k]));
 =

     return 0;
 }

Modified: trunk/src/pulsecore/memblock.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/memblock.c?=
rev=3D1459&root=3Dpulseaudio&r1=3D1458&r2=3D1459&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/pulsecore/memblock.c (original)
+++ trunk/src/pulsecore/memblock.c Sun May 27 22:38:14 2007
@@ -114,40 +114,40 @@
     assert(b);
     assert(b->pool);
 =

-    AO_fetch_and_add1_release_write(&b->pool->stat.n_allocated);
-    AO_fetch_and_add_release_write(&b->pool->stat.allocated_size, (AO_t) b=
->length);
-
-    AO_fetch_and_add1_release_write(&b->pool->stat.n_accumulated);
-    AO_fetch_and_add_release_write(&b->pool->stat.accumulated_size, (AO_t)=
 b->length);
+    pa_atomic_inc(&b->pool->stat.n_allocated);
+    pa_atomic_add(&b->pool->stat.allocated_size, b->length);
+
+    pa_atomic_inc(&b->pool->stat.n_accumulated);
+    pa_atomic_add(&b->pool->stat.accumulated_size, b->length);
 =

     if (b->type =3D=3D PA_MEMBLOCK_IMPORTED) {
-        AO_fetch_and_add1_release_write(&b->pool->stat.n_imported);
-        AO_fetch_and_add_release_write(&b->pool->stat.imported_size, (AO_t=
) b->length);
-    }
-
-    AO_fetch_and_add1_release_write(&b->pool->stat.n_allocated_by_type[b->=
type]);
-    AO_fetch_and_add1_release_write(&b->pool->stat.n_accumulated_by_type[b=
->type]);
+        pa_atomic_inc(&b->pool->stat.n_imported);
+        pa_atomic_add(&b->pool->stat.imported_size, b->length);
+    }
+
+    pa_atomic_inc(&b->pool->stat.n_allocated_by_type[b->type]);
+    pa_atomic_inc(&b->pool->stat.n_accumulated_by_type[b->type]);
 }
 =

 static void stat_remove(pa_memblock *b) {
     assert(b);
     assert(b->pool);
 =

-    assert(AO_load_acquire_read(&b->pool->stat.n_allocated) > 0);
-    assert(AO_load_acquire_read(&b->pool->stat.allocated_size) >=3D (AO_t)=
 b->length);
-
-    AO_fetch_and_sub1_release_write(&b->pool->stat.n_allocated);
-    AO_fetch_and_add_release_write(&b->pool->stat.allocated_size,  (AO_t) =
(-b->length));
+    assert(pa_atomic_load(&b->pool->stat.n_allocated) > 0);
+    assert(pa_atomic_load(&b->pool->stat.allocated_size) >=3D (int) b->len=
gth);
+
+    pa_atomic_dec(&b->pool->stat.n_allocated);
+    pa_atomic_sub(&b->pool->stat.allocated_size,  b->length);
 =

     if (b->type =3D=3D PA_MEMBLOCK_IMPORTED) {
-        assert(AO_load_acquire_read(&b->pool->stat.n_imported) > 0);
-        assert(AO_load_acquire_read(&b->pool->stat.imported_size) >=3D (AO=
_t) b->length);
-
-        AO_fetch_and_sub1_release_write(&b->pool->stat.n_imported);
-        AO_fetch_and_add_release_write(&b->pool->stat.imported_size, (AO_t=
)  (-b->length));
-    }
-
-    AO_fetch_and_sub1_release_write(&b->pool->stat.n_allocated_by_type[b->=
type]);
+        assert(pa_atomic_load(&b->pool->stat.n_imported) > 0);
+        assert(pa_atomic_load(&b->pool->stat.imported_size) >=3D (int) b->=
length);
+
+        pa_atomic_dec(&b->pool->stat.n_imported);
+        pa_atomic_sub(&b->pool->stat.imported_size, b->length);
+    }
+
+    pa_atomic_dec(&b->pool->stat.n_allocated_by_type[b->type]);
 }
 =

 static pa_memblock *memblock_new_appended(pa_mempool *p, size_t length);
@@ -193,7 +193,7 @@
         slot =3D (struct mempool_slot*) ((uint8_t*) p->memory.ptr + (p->bl=
ock_size * p->n_init++));
     else {
         pa_log_debug("Pool full");
-        AO_fetch_and_add1_release_write(&p->stat.n_pool_full);
+        pa_atomic_inc(&p->stat.n_pool_full);
         return NULL;
     }
 =

@@ -249,7 +249,7 @@
         b->data =3D mempool_slot_data(slot);
     } else {
         pa_log_debug("Memory block too large for pool: %u > %u", length, p=
->block_size - sizeof(struct mempool_slot));
-        AO_fetch_and_add1_release_write(&p->stat.n_too_large_for_pool);
+        pa_atomic_inc(&p->stat.n_too_large_for_pool);
         return NULL;
     }
 =

@@ -372,7 +372,7 @@
 static void memblock_make_local(pa_memblock *b) {
     assert(b);
 =

-    AO_fetch_and_sub1_release_write(&b->pool->stat.n_allocated_by_type[b->=
type]);
+    pa_atomic_dec(&b->pool->stat.n_allocated_by_type[b->type]);
 =

     if (b->length <=3D b->pool->block_size - sizeof(struct mempool_slot)) {
         struct mempool_slot *slot;
@@ -398,8 +398,8 @@
     b->data =3D pa_xmemdup(b->data, b->length);
 =

 finish:
-    AO_fetch_and_add1_release_write(&b->pool->stat.n_allocated_by_type[b->=
type]);
-    AO_fetch_and_add1_release_write(&b->pool->stat.n_accumulated_by_type[b=
->type]);
+    pa_atomic_inc(&b->pool->stat.n_allocated_by_type[b->type]);
+    pa_atomic_inc(&b->pool->stat.n_accumulated_by_type[b->type]);
 }
 =

 void pa_memblock_unref_fixed(pa_memblock *b) {
@@ -419,10 +419,10 @@
     assert(b);
     assert(b->type =3D=3D PA_MEMBLOCK_IMPORTED);
 =

-    assert(AO_load_acquire_read(&b->pool->stat.n_imported) > 0);
-    assert(AO_load_acquire_read(&b->pool->stat.imported_size) >=3D (AO_t) =
b->length);
-    AO_fetch_and_sub1_release_write(&b->pool->stat.n_imported);
-    AO_fetch_and_add_release_write(&b->pool->stat.imported_size, (AO_t) - =
b->length);
+    assert(pa_atomic_load(&b->pool->stat.n_imported) > 0);
+    assert(pa_atomic_load(&b->pool->stat.imported_size) >=3D (int) b->leng=
th);
+    pa_atomic_dec(&b->pool->stat.n_imported);
+    pa_atomic_sub(&b->pool->stat.imported_size, b->length);
 =

     seg =3D b->per_type.imported.segment;
     assert(seg);
@@ -486,7 +486,7 @@
     while (p->exports)
         pa_memexport_free(p->exports);
 =

-    if (AO_load_acquire_read(&p->stat.n_allocated) > 0)
+    if (pa_atomic_load(&p->stat.n_allocated) > 0)
         pa_log_warn("WARNING! Memory pool destroyed but not all memory blo=
cks freed!");
 =

     pa_shm_free(&p->memory);
@@ -684,11 +684,11 @@
 =

 /*     pa_log("Processing release for %u", id); */
 =

-    assert(AO_load_acquire_read(&e->pool->stat.n_exported) > 0);
-    assert(AO_load_acquire_read(&e->pool->stat.exported_size) >=3D (AO_t) =
e->slots[id].block->length);
-
-    AO_fetch_and_sub1_release_write(&e->pool->stat.n_exported);
-    AO_fetch_and_add_release_write(&e->pool->stat.exported_size, (AO_t) -e=
->slots[id].block->length);
+    assert(pa_atomic_load(&e->pool->stat.n_exported) > 0);
+    assert(pa_atomic_load(&e->pool->stat.exported_size) >=3D (int) e->slot=
s[id].block->length);
+
+    pa_atomic_dec(&e->pool->stat.n_exported);
+    pa_atomic_sub(&e->pool->stat.exported_size, e->slots[id].block->length=
);
 =

     pa_memblock_unref(e->slots[id].block);
     e->slots[id].block =3D NULL;
@@ -785,8 +785,8 @@
     *offset =3D (uint8_t*) b->data - (uint8_t*) memory->ptr;
     *size =3D b->length;
 =

-    AO_fetch_and_add1_release_write(&e->pool->stat.n_exported);
-    AO_fetch_and_add_release_write(&e->pool->stat.exported_size, (AO_t) b-=
>length);
+    pa_atomic_inc(&e->pool->stat.n_exported);
+    pa_atomic_add(&e->pool->stat.exported_size, b->length);
 =

     return 0;
 }

Modified: trunk/src/pulsecore/memblock.h
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/memblock.h?=
rev=3D1459&root=3Dpulseaudio&r1=3D1458&r2=3D1459&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/pulsecore/memblock.h (original)
+++ trunk/src/pulsecore/memblock.h Sun May 27 22:38:14 2007
@@ -30,6 +30,7 @@
 =

 #include <pulsecore/llist.h>
 #include <pulsecore/refcnt.h>
+#include <pulsecore/atomic.h>
 =

 /* A pa_memblock is a reference counted memory block. PulseAudio
  * passed references to pa_memblocks around instead of copying
@@ -82,20 +83,20 @@
  * n_accumulated is not yet. Take these values with a grain of salt,
  * threy are here for purely statistical reasons.*/
 struct pa_mempool_stat {
-    AO_t n_allocated;
-    AO_t n_accumulated;
-    AO_t n_imported;
-    AO_t n_exported;
-    AO_t allocated_size;
-    AO_t accumulated_size;
-    AO_t imported_size;
-    AO_t exported_size;
+    pa_atomic_int_t n_allocated;
+    pa_atomic_int_t n_accumulated;
+    pa_atomic_int_t n_imported;
+    pa_atomic_int_t n_exported;
+    pa_atomic_int_t allocated_size;
+    pa_atomic_int_t accumulated_size;
+    pa_atomic_int_t imported_size;
+    pa_atomic_int_t exported_size;
 =

-    AO_t n_too_large_for_pool;
-    AO_t n_pool_full;
+    pa_atomic_int_t n_too_large_for_pool;
+    pa_atomic_int_t n_pool_full;
 =

-    AO_t n_allocated_by_type[PA_MEMBLOCK_TYPE_MAX];
-    AO_t n_accumulated_by_type[PA_MEMBLOCK_TYPE_MAX];
+    pa_atomic_int_t n_allocated_by_type[PA_MEMBLOCK_TYPE_MAX];
+    pa_atomic_int_t n_accumulated_by_type[PA_MEMBLOCK_TYPE_MAX];
 };
 =

 /* Allocate a new memory block of type PA_MEMBLOCK_MEMPOOL or PA_MEMBLOCK_=
APPENDED, depending on the size */

Modified: trunk/src/pulsecore/protocol-native.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/pulsecore/protocol-na=
tive.c?rev=3D1459&root=3Dpulseaudio&r1=3D1458&r2=3D1459&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/pulsecore/protocol-native.c (original)
+++ trunk/src/pulsecore/protocol-native.c Sun May 27 22:38:14 2007
@@ -1116,10 +1116,10 @@
     stat =3D pa_mempool_get_stat(c->protocol->core->mempool);
 =

     reply =3D reply_new(tag);
-    pa_tagstruct_putu32(reply, (uint32_t) AO_load_acquire_read((AO_t*) &st=
at->n_allocated));
-    pa_tagstruct_putu32(reply, (uint32_t) AO_load_acquire_read((AO_t*) &st=
at->allocated_size));
-    pa_tagstruct_putu32(reply, (uint32_t) AO_load_acquire_read((AO_t*) &st=
at->n_accumulated));
-    pa_tagstruct_putu32(reply, (uint32_t) AO_load_acquire_read((AO_t*) &st=
at->accumulated_size));
+    pa_tagstruct_putu32(reply, (uint32_t) pa_atomic_load(&stat->n_allocate=
d));
+    pa_tagstruct_putu32(reply, (uint32_t) pa_atomic_load(&stat->allocated_=
size));
+    pa_tagstruct_putu32(reply, (uint32_t) pa_atomic_load(&stat->n_accumula=
ted));
+    pa_tagstruct_putu32(reply, (uint32_t) pa_atomic_load(&stat->accumulate=
d_size));
     pa_tagstruct_putu32(reply, pa_scache_total_size(c->protocol->core));
     pa_pstream_send_tagstruct(c->pstream, reply);
 }

Modified: trunk/src/tests/memblock-test.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/trunk/src/tests/memblock-test.c=
?rev=3D1459&root=3Dpulseaudio&r1=3D1458&r2=3D1459&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/src/tests/memblock-test.c (original)
+++ trunk/src/tests/memblock-test.c Sun May 27 22:38:14 2007
@@ -46,24 +46,24 @@
            "n_accumulated =3D %u\n"
            "n_imported =3D %u\n"
            "n_exported =3D %u\n"
-           "allocated_size =3D %lu\n"
-           "accumulated_size =3D %lu\n"
-           "imported_size =3D %lu\n"
-           "exported_size =3D %lu\n"
+           "allocated_size =3D %u\n"
+           "accumulated_size =3D %u\n"
+           "imported_size =3D %u\n"
+           "exported_size =3D %u\n"
            "n_too_large_for_pool =3D %u\n"
            "n_pool_full =3D %u\n"
            "}\n",
            text,
-           (unsigned) AO_load_acquire_read((AO_t*) &s->n_allocated),
-           (unsigned) AO_load_acquire_read((AO_t*) &s->n_accumulated),
-           (unsigned) AO_load_acquire_read((AO_t*) &s->n_imported),
-           (unsigned) AO_load_acquire_read((AO_t*) &s->n_exported),
-           (unsigned long) AO_load_acquire_read((AO_t*) &s->allocated_size=
),
-           (unsigned long) AO_load_acquire_read((AO_t*) &s->accumulated_si=
ze),
-           (unsigned long) AO_load_acquire_read((AO_t*) &s->imported_size),
-           (unsigned long) AO_load_acquire_read((AO_t*) &s->exported_size),
-           (unsigned) AO_load_acquire_read((AO_t*) &s->n_too_large_for_poo=
l),
-           (unsigned) AO_load_acquire_read((AO_t*) &s->n_pool_full));
+           (unsigned) pa_atomic_load(&s->n_allocated),
+           (unsigned) pa_atomic_load(&s->n_accumulated),
+           (unsigned) pa_atomic_load(&s->n_imported),
+           (unsigned) pa_atomic_load(&s->n_exported),
+           (unsigned) pa_atomic_load(&s->allocated_size),
+           (unsigned) pa_atomic_load(&s->accumulated_size),
+           (unsigned) pa_atomic_load(&s->imported_size),
+           (unsigned) pa_atomic_load(&s->exported_size),
+           (unsigned) pa_atomic_load(&s->n_too_large_for_pool),
+           (unsigned) pa_atomic_load(&s->n_pool_full));
 }
 =

 int main(int argc, char *argv[]) {




More information about the pulseaudio-commits mailing list