summaryrefslogtreecommitdiffstats
path: root/utils/sysrepo-plugins/hicn-plugin/plugin/model/tlock.c
blob: d27ae6492594adbe5b02e96e9a9ce2261c21f729 (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 tlock(int Lock_Number ){

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

}

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