aboutsummaryrefslogtreecommitdiffstats
path: root/ctrl/sysrepo-plugins/hicn-plugin/plugin/model/tlock.c
blob: c3c225ef7004439173302a8c1855180f8dd657e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#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]++; }