Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<locks> Added support for bakerylock #302

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ include $(LIB_DIR)/libc/build.mk
include $(LIB_DIR)/libresource/build.mk
include $(LIB_DIR)/libsyslog/build.mk
include $(LIB_DIR)/libccfs/build.mk
include $(LIB_DIR)/liblocks/build.mk
#==================================================

include $(LIB_DIR)/libnmath/build.mk
Expand Down
44 changes: 44 additions & 0 deletions src/lib/liblocks/bakerylock.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

#include <status.h>
#include <stdint.h>
#include <arch.h>
#include <lock/bakerylock.h>

void bakerylock_acquire(bakerylock_t *key)
{
unsigned int tid = arch_core_index();
key->protect[tid] = 1;
arch_dmb();

unsigned int i, n_cust, n_max = 0;
for(i = 0; i < N_CORES; i++)
{
n_cust = key->thread_count[i];
n_max = n_cust > n_max ? n_cust : n_max;
}

key->thread_count[tid] = n_max + 1;

arch_dmb();
key->protect[tid] = 0;
arch_dmb();

for(i = 0; i < N_CORES; i++)
{
while(key->protect[i]);
arch_dmb();

while(key->thread_count[i] && (
(key->thread_count[i] < key->thread_count[tid]) ||
((key->thread_count[i] == key->thread_count[tid]) &&
(i < tid))));
}
}

void bakerylock_release(bakerylock_t *key)
{
unsigned int tid = arch_core_index();
arch_dmb();
key->thread_count[tid] = 0;
}

20 changes: 20 additions & 0 deletions src/lib/liblocks/build.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# CYANCORE LICENSE
# Copyrights (C) 2024, Cyancore Team
#
# File Name : build.mk
# Description : This file accumulates sources of locks
# Primary Author : Akash Kollipara [[email protected]]
# Organisation : Cyancore Core-Team
#

LIBLOCKS_PATH := $(GET_PATH)
LIB_OBJS :=

LIB += liblocks.a
LIB_INCLUDE += $(LIBLOCKS_PATH)/include
DEP_LIBS_ARG += -llocks


DIR := $(LIBLOCKS_PATH)
include mk/lib.mk
16 changes: 16 additions & 0 deletions src/lib/liblocks/include/lock/bakerylock.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

#pragma once
#define _BAKERYLOCK_H_

#include <stdbool.h>

#pragma pack(1)
typedef struct
{
volatile uint8_t thread_count[N_CORES];
volatile bool protect[N_CORES];
} bakerylock_t;
#pragma pack()

extern void bakerylock_acquire(bakerylock_t *);
extern void bakerylock_release(bakerylock_t *);
File renamed without changes.
Loading