summaryrefslogtreecommitdiffstats
path: root/ctrl/sysrepo-plugins/hicn-light/plugin/model/tlock.c
blob: 2f7b11efacdcd09f3b853e9fe98deb4d0017ab65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include"tlock.h"


void Ticket_init ( int Lock_Number , long int init ){

__atomic_store( &En[Lock_Number] , &init , __ATOMIC_SEQ_CST );
__atomic_store( &De[Lock_Number] , &init , __ATOMIC_SEQ_CST );
//En[Lock_Number]=init;
//De[Lock_Number]=init;
}

void Ticket_Lock(int Lock_Number ){

 int my_ticket =   __sync_fetch_and_add(&En[Lock_Number] , 1  );
 while (    my_ticket != De[ Lock_Number ]  ) {};

}

void Ticket_Unlock(int Lock_Number ){
De[Lock_Number]++;
}