-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<locks> Added support for bakerylock
- Added sources for bakerylock - Moved lock realted files to liblocks for adding more lock sources Issue: #301
- Loading branch information
1 parent
7806018
commit 8ecf2f5
Showing
6 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
File renamed without changes.