summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog3
-rw-r--r--NEWS2
-rw-r--r--src/lib/eina/eina_share_common.c52
-rw-r--r--src/lib/eina/eina_stringshare.c18
4 files changed, 38 insertions, 37 deletions
diff --git a/ChangeLog b/ChangeLog
index f700f93a73..fcedcf49aa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,8 @@
12013-10-11 Cedric Bail 12013-10-11 Cedric Bail
2 2
3 * Eina: add Eina_Spinlock API, 3 * Eina: add Eina_Spinlock API,
4 use Eina_Spinlock in Eina_Log. 4 use Eina_Spinlock in Eina_Log,
5 replace Eina_Lock by Eina_Spinlock in Eina_Stringshare.
5 6
62013-10-10 Carsten Haitzler (The Rasterman) 72013-10-10 Carsten Haitzler (The Rasterman)
7 8
diff --git a/NEWS b/NEWS
index e49464b0cf..509d17c2c7 100644
--- a/NEWS
+++ b/NEWS
@@ -198,7 +198,7 @@ Improvements:
198 - Eina_Tiler now take tile size into account. 198 - Eina_Tiler now take tile size into account.
199 - Improve support for 64bits system. 199 - Improve support for 64bits system.
200 - eina_strlcat now work with a NULL source. 200 - eina_strlcat now work with a NULL source.
201 - Use Eina_Spinlock for eina_log. 201 - Use Eina_Spinlock for eina_log, eina_stringshare.
202 * Eet: 202 * Eet:
203 - Display more information with eet -l -v. 203 - Display more information with eet -l -v.
204 - Force thread to always run during eet_cache_concurrency test. 204 - Force thread to always run during eet_cache_concurrency test.
diff --git a/src/lib/eina/eina_share_common.c b/src/lib/eina/eina_share_common.c
index c2b64acc75..0682b6e4e9 100644
--- a/src/lib/eina/eina_share_common.c
+++ b/src/lib/eina/eina_share_common.c
@@ -174,7 +174,7 @@ struct _Eina_Share_Common_Head
174 174
175Eina_Bool _share_common_threads_activated = EINA_FALSE; 175Eina_Bool _share_common_threads_activated = EINA_FALSE;
176 176
177static Eina_Lock _mutex_big; 177static Eina_Spinlock _mutex_big;
178 178
179#ifdef EINA_STRINGSHARE_USAGE 179#ifdef EINA_STRINGSHARE_USAGE
180 180
@@ -256,9 +256,9 @@ eina_share_common_population_nolock_add(Eina_Share *share, int slen)
256void 256void
257eina_share_common_population_add(Eina_Share *share, int slen) 257eina_share_common_population_add(Eina_Share *share, int slen)
258{ 258{
259 eina_lock_take(&_mutex_big); 259 eina_spinlock_take(&_mutex_big);
260 eina_share_common_population_nolock_add(share, slen); 260 eina_share_common_population_nolock_add(share, slen);
261 eina_lock_release(&_mutex_big); 261 eina_spinlock_release(&_mutex_big);
262} 262}
263 263
264static void 264static void
@@ -272,9 +272,9 @@ eina_share_common_population_nolock_del(Eina_Share *share, int slen)
272void 272void
273eina_share_common_population_del(Eina_Share *share, int slen) 273eina_share_common_population_del(Eina_Share *share, int slen)
274{ 274{
275 eina_lock_take(&_mutex_big); 275 eina_spinlock_take(&_mutex_big);
276 eina_share_common_population_nolock_del(chare, slen); 276 eina_share_common_population_nolock_del(chare, slen);
277 eina_lock_release(&_mutex_big); 277 eina_spinlock_release(&_mutex_big);
278} 278}
279 279
280static void 280static void
@@ -634,7 +634,7 @@ eina_share_common_init(Eina_Share **_share,
634 if (_eina_share_common_count++ != 0) 634 if (_eina_share_common_count++ != 0)
635 return EINA_TRUE; 635 return EINA_TRUE;
636 636
637 eina_lock_new(&_mutex_big); 637 eina_spinlock_new(&_mutex_big);
638 return EINA_TRUE; 638 return EINA_TRUE;
639 639
640 on_error: 640 on_error:
@@ -659,7 +659,7 @@ eina_share_common_shutdown(Eina_Share **_share)
659 unsigned int i; 659 unsigned int i;
660 Eina_Share *share = *_share; 660 Eina_Share *share = *_share;
661 661
662 eina_lock_take(&_mutex_big); 662 eina_spinlock_take(&_mutex_big);
663 663
664 _eina_share_common_population_stats(share); 664 _eina_share_common_population_stats(share);
665 665
@@ -676,7 +676,7 @@ eina_share_common_shutdown(Eina_Share **_share)
676 676
677 _eina_share_common_population_shutdown(share); 677 _eina_share_common_population_shutdown(share);
678 678
679 eina_lock_release(&_mutex_big); 679 eina_spinlock_release(&_mutex_big);
680 680
681 free(*_share); 681 free(*_share);
682 *_share = NULL; 682 *_share = NULL;
@@ -685,7 +685,7 @@ eina_share_common_shutdown(Eina_Share **_share)
685 if (--_eina_share_common_count != 0) 685 if (--_eina_share_common_count != 0)
686 return EINA_TRUE; 686 return EINA_TRUE;
687 687
688 eina_lock_free(&_mutex_big); 688 eina_spinlock_free(&_mutex_big);
689 689
690 return EINA_TRUE; 690 return EINA_TRUE;
691} 691}
@@ -752,7 +752,7 @@ eina_share_common_add_length(Eina_Share *share,
752 752
753 hash = eina_hash_superfast(str, slen); 753 hash = eina_hash_superfast(str, slen);
754 754
755 eina_lock_take(&_mutex_big); 755 eina_spinlock_take(&_mutex_big);
756 p_bucket = share->share->buckets + EINA_SHARE_COMMON_BUCKET_IDX(hash); 756 p_bucket = share->share->buckets + EINA_SHARE_COMMON_BUCKET_IDX(hash);
757 757
758 ed = _eina_share_common_find_hash(*p_bucket, EINA_SHARE_COMMON_NODE_HASH(hash)); 758 ed = _eina_share_common_find_hash(*p_bucket, EINA_SHARE_COMMON_NODE_HASH(hash));
@@ -764,27 +764,27 @@ eina_share_common_add_length(Eina_Share *share,
764 str, 764 str,
765 slen, 765 slen,
766 null_size); 766 null_size);
767 eina_lock_release(&_mutex_big); 767 eina_spinlock_release(&_mutex_big);
768 return s; 768 return s;
769 } 769 }
770 770
771 EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_lock_release(&_mutex_big), NULL); 771 EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_spinlock_release(&_mutex_big), NULL);
772 772
773 el = _eina_share_common_head_find(ed, str, slen); 773 el = _eina_share_common_head_find(ed, str, slen);
774 if (el) 774 if (el)
775 { 775 {
776 EINA_MAGIC_CHECK_SHARE_COMMON_NODE(el, 776 EINA_MAGIC_CHECK_SHARE_COMMON_NODE(el,
777 share->node_magic, 777 share->node_magic,
778 eina_lock_release(&_mutex_big)); 778 eina_spinlock_release(&_mutex_big));
779 el->references++; 779 el->references++;
780 eina_lock_release(&_mutex_big); 780 eina_spinlock_release(&_mutex_big);
781 return el->str; 781 return el->str;
782 } 782 }
783 783
784 el = _eina_share_common_node_alloc(slen, null_size); 784 el = _eina_share_common_node_alloc(slen, null_size);
785 if (!el) 785 if (!el)
786 { 786 {
787 eina_lock_release(&_mutex_big); 787 eina_spinlock_release(&_mutex_big);
788 return NULL; 788 return NULL;
789 } 789 }
790 790
@@ -793,7 +793,7 @@ eina_share_common_add_length(Eina_Share *share,
793 ed->head = el; 793 ed->head = el;
794 _eina_share_common_population_head_add(share, ed); 794 _eina_share_common_population_head_add(share, ed);
795 795
796 eina_lock_release(&_mutex_big); 796 eina_spinlock_release(&_mutex_big);
797 797
798 return el->str; 798 return el->str;
799} 799}
@@ -806,18 +806,18 @@ eina_share_common_ref(Eina_Share *share, const char *str)
806 if (!str) 806 if (!str)
807 return NULL; 807 return NULL;
808 808
809 eina_lock_take(&_mutex_big); 809 eina_spinlock_take(&_mutex_big);
810 node = _eina_share_common_node_from_str(str, share->node_magic); 810 node = _eina_share_common_node_from_str(str, share->node_magic);
811 if (!node) 811 if (!node)
812 { 812 {
813 eina_lock_release(&_mutex_big); 813 eina_spinlock_release(&_mutex_big);
814 return str; 814 return str;
815 } 815 }
816 node->references++; 816 node->references++;
817 817
818 eina_share_common_population_nolock_add(share, node->length); 818 eina_share_common_population_nolock_add(share, node->length);
819 819
820 eina_lock_release(&_mutex_big); 820 eina_spinlock_release(&_mutex_big);
821 821
822 return str; 822 return str;
823} 823}
@@ -834,7 +834,7 @@ eina_share_common_del(Eina_Share *share, const char *str)
834 if (!str) 834 if (!str)
835 return EINA_TRUE; 835 return EINA_TRUE;
836 836
837 eina_lock_take(&_mutex_big); 837 eina_spinlock_take(&_mutex_big);
838 838
839 node = _eina_share_common_node_from_str(str, share->node_magic); 839 node = _eina_share_common_node_from_str(str, share->node_magic);
840 if (!node) 840 if (!node)
@@ -845,7 +845,7 @@ eina_share_common_del(Eina_Share *share, const char *str)
845 if (node->references > 1) 845 if (node->references > 1)
846 { 846 {
847 node->references--; 847 node->references--;
848 eina_lock_release(&_mutex_big); 848 eina_spinlock_release(&_mutex_big);
849 return EINA_TRUE; 849 return EINA_TRUE;
850 } 850 }
851 851
@@ -855,7 +855,7 @@ eina_share_common_del(Eina_Share *share, const char *str)
855 if (!ed) 855 if (!ed)
856 goto on_error; 856 goto on_error;
857 857
858 EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_lock_release(&_mutex_big), EINA_FALSE); 858 EINA_MAGIC_CHECK_SHARE_COMMON_HEAD(ed, eina_spinlock_release(&_mutex_big), EINA_FALSE);
859 859
860 if (node != &ed->builtin_node) 860 if (node != &ed->builtin_node)
861 { 861 {
@@ -872,12 +872,12 @@ eina_share_common_del(Eina_Share *share, const char *str)
872 else 872 else
873 _eina_share_common_population_head_del(share, ed); 873 _eina_share_common_population_head_del(share, ed);
874 874
875 eina_lock_release(&_mutex_big); 875 eina_spinlock_release(&_mutex_big);
876 876
877 return EINA_TRUE; 877 return EINA_TRUE;
878 878
879on_error: 879on_error:
880 eina_lock_release(&_mutex_big); 880 eina_spinlock_release(&_mutex_big);
881 /* possible segfault happened before here, but... */ 881 /* possible segfault happened before here, but... */
882 return EINA_FALSE; 882 return EINA_FALSE;
883} 883}
@@ -913,7 +913,7 @@ eina_share_common_dump(Eina_Share *share, void (*additional_dump)(
913 printf("DDD: len ref string\n"); 913 printf("DDD: len ref string\n");
914 printf("DDD:-------------------\n"); 914 printf("DDD:-------------------\n");
915 915
916 eina_lock_take(&_mutex_big); 916 eina_spinlock_take(&_mutex_big);
917 for (i = 0; i < EINA_SHARE_COMMON_BUCKETS; i++) 917 for (i = 0; i < EINA_SHARE_COMMON_BUCKETS; i++)
918 { 918 {
919 if (!share->share->buckets[i]) 919 if (!share->share->buckets[i])
@@ -958,7 +958,7 @@ eina_share_common_dump(Eina_Share *share, void (*additional_dump)(
958 share->population_group[i].max); 958 share->population_group[i].max);
959#endif 959#endif
960 960
961 eina_lock_release(&_mutex_big); 961 eina_spinlock_release(&_mutex_big);
962} 962}
963 963
964/** 964/**
diff --git a/src/lib/eina/eina_stringshare.c b/src/lib/eina/eina_stringshare.c
index 9f8d10e8cd..2232fa9395 100644
--- a/src/lib/eina/eina_stringshare.c
+++ b/src/lib/eina/eina_stringshare.c
@@ -69,7 +69,7 @@ static Eina_Share *stringshare_share;
69static const char EINA_MAGIC_STRINGSHARE_NODE_STR[] = "Eina Stringshare Node"; 69static const char EINA_MAGIC_STRINGSHARE_NODE_STR[] = "Eina Stringshare Node";
70 70
71extern Eina_Bool _share_common_threads_activated; 71extern Eina_Bool _share_common_threads_activated;
72static Eina_Lock _mutex_small; 72static Eina_Spinlock _mutex_small;
73 73
74/* Stringshare optimizations */ 74/* Stringshare optimizations */
75static const unsigned char _eina_stringshare_single[512] = { 75static const unsigned char _eina_stringshare_single[512] = {
@@ -396,7 +396,7 @@ error:
396static void 396static void
397_eina_stringshare_small_init(void) 397_eina_stringshare_small_init(void)
398{ 398{
399 eina_lock_new(&_mutex_small); 399 eina_spinlock_new(&_mutex_small);
400 memset(&_eina_small_share, 0, sizeof(_eina_small_share)); 400 memset(&_eina_small_share, 0, sizeof(_eina_small_share));
401} 401}
402 402
@@ -428,7 +428,7 @@ _eina_stringshare_small_shutdown(void)
428 *p_bucket = NULL; 428 *p_bucket = NULL;
429 } 429 }
430 430
431 eina_lock_free(&_mutex_small); 431 eina_spinlock_free(&_mutex_small);
432} 432}
433 433
434static void 434static void
@@ -586,9 +586,9 @@ eina_stringshare_del(Eina_Stringshare *str)
586 else if (slen < 4) 586 else if (slen < 4)
587 { 587 {
588 eina_share_common_population_del(stringshare_share, slen); 588 eina_share_common_population_del(stringshare_share, slen);
589 eina_lock_take(&_mutex_small); 589 eina_spinlock_take(&_mutex_small);
590 _eina_stringshare_small_del(str, slen); 590 _eina_stringshare_small_del(str, slen);
591 eina_lock_release(&_mutex_small); 591 eina_spinlock_release(&_mutex_small);
592 592
593 return; 593 return;
594 } 594 }
@@ -619,9 +619,9 @@ eina_stringshare_add_length(const char *str, unsigned int slen)
619 const char *s; 619 const char *s;
620 620
621 eina_share_common_population_add(stringshare_share, slen); 621 eina_share_common_population_add(stringshare_share, slen);
622 eina_lock_take(&_mutex_small); 622 eina_spinlock_take(&_mutex_small);
623 s = _eina_stringshare_small_add(str, slen); 623 s = _eina_stringshare_small_add(str, slen);
624 eina_lock_release(&_mutex_small); 624 eina_spinlock_release(&_mutex_small);
625 625
626 return s; 626 return s;
627 } 627 }
@@ -738,9 +738,9 @@ eina_stringshare_ref(Eina_Stringshare *str)
738 const char *s; 738 const char *s;
739 739
740 eina_share_common_population_add(stringshare_share, slen); 740 eina_share_common_population_add(stringshare_share, slen);
741 eina_lock_take(&_mutex_small); 741 eina_spinlock_take(&_mutex_small);
742 s = _eina_stringshare_small_add(str, slen); 742 s = _eina_stringshare_small_add(str, slen);
743 eina_lock_release(&_mutex_small); 743 eina_spinlock_release(&_mutex_small);
744 744
745 return s; 745 return s;
746 } 746 }