|
54 | 54 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a)) |
55 | 55 | #endif |
56 | 56 |
|
57 | | -#ifndef unlikely |
58 | | -#define unlikely(x) __builtin_expect(!!(x), 0) |
59 | | -#endif |
60 | | - |
61 | | -#ifndef likely |
62 | | -#define likely(x) __builtin_expect(!!(x), 1) |
63 | | -#endif |
64 | | - |
65 | 57 | enum { |
66 | 58 | STATS_ENTRY_FLAG_REGISTERED = 1 << 0, |
67 | 59 | STATS_ENTRY_FLAG_DIR = 1 << 1, |
@@ -779,32 +771,17 @@ static int register_item(struct procstat_context *context, |
779 | 771 | struct procstat_item *item, |
780 | 772 | struct procstat_directory *parent) |
781 | 773 | { |
782 | | - if (likely(parent)) { |
| 774 | + pthread_mutex_lock(&context->global_lock); |
| 775 | + if (parent) { |
783 | 776 | struct procstat_item *duplicate; |
784 | | - bool locked = false; |
785 | | - |
786 | | - if (unlikely(root_directory(context, parent))) { |
787 | | - /* Only root directory can be modified concurrently by different threads */ |
788 | | - pthread_mutex_lock(&context->global_lock); |
789 | | - locked = true; |
790 | | - } |
791 | 777 |
|
792 | 778 | duplicate = lookup_item_locked(parent, procstat_item_name(item), item->name_hash); |
793 | | - if (unlikely(duplicate)) { |
794 | | - if (locked) |
795 | | - pthread_mutex_unlock(&context->global_lock); |
| 779 | + if (duplicate) { |
| 780 | + pthread_mutex_unlock(&context->global_lock); |
796 | 781 | return EEXIST; |
797 | 782 | } |
798 | | - |
799 | | - if (likely(!locked)) |
800 | | - pthread_mutex_lock(&context->global_lock); |
801 | | - |
802 | 783 | list_add_tail(&item->entry, &parent->children); |
803 | | - } else { |
804 | | - pthread_mutex_lock(&context->global_lock); |
805 | 784 | } |
806 | | - |
807 | | - |
808 | 785 | item->flags |= STATS_ENTRY_FLAG_REGISTERED; |
809 | 786 | item->refcnt = 1; |
810 | 787 | item->parent = parent; |
|
0 commit comments