summaryrefslogtreecommitdiffstats
path: root/utils/sysrepo-plugins/hicn-plugin/plugin/model/tlock.c
blob: d870adf7580c8f086e9b855bb2fddfaa6c054027 (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]++;
}