Skip to content

Commit c608c63

Browse files
committed
Revert "Merge pull request #32 from LightBitsLabs/anton/create_lookup_unlocked"
This reverts commit 32af7d0, reversing changes made to 0eecd8a.
1 parent 32af7d0 commit c608c63

File tree

1 file changed

+4
-27
lines changed

1 file changed

+4
-27
lines changed

src/procstat.c

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,6 @@
5454
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(*a))
5555
#endif
5656

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-
6557
enum {
6658
STATS_ENTRY_FLAG_REGISTERED = 1 << 0,
6759
STATS_ENTRY_FLAG_DIR = 1 << 1,
@@ -779,32 +771,17 @@ static int register_item(struct procstat_context *context,
779771
struct procstat_item *item,
780772
struct procstat_directory *parent)
781773
{
782-
if (likely(parent)) {
774+
pthread_mutex_lock(&context->global_lock);
775+
if (parent) {
783776
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-
}
791777

792778
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);
796781
return EEXIST;
797782
}
798-
799-
if (likely(!locked))
800-
pthread_mutex_lock(&context->global_lock);
801-
802783
list_add_tail(&item->entry, &parent->children);
803-
} else {
804-
pthread_mutex_lock(&context->global_lock);
805784
}
806-
807-
808785
item->flags |= STATS_ENTRY_FLAG_REGISTERED;
809786
item->refcnt = 1;
810787
item->parent = parent;

0 commit comments

Comments
 (0)