Nebula
Loading...
Searching...
No Matches
linuxrendezvous.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
11#include "core/types.h"
12#include <semaphore.h>
13
14//------------------------------------------------------------------------------
15namespace Linux
16{
18{
19public:
24
26 void MasterArrive();
28 void SlaveArrive();
29
30private:
31 sem_t semMaster;
32 sem_t semSlave;
33};
34
35//------------------------------------------------------------------------------
38inline
40{
41 int res;
42 res = sem_init(&this->semMaster, 0, 0);
43 n_assert(0 == res);
44 res = sem_init(&this->semSlave, 0, 0);
45 n_assert(0 == res);
46}
47
48//------------------------------------------------------------------------------
51inline
53{
54 sem_destroy(&this->semMaster);
55 sem_destroy(&this->semSlave);
56}
57
58//------------------------------------------------------------------------------
61inline void
63{
64 n_assert(sem_post(&this->semMaster) == 0);
65 n_assert(sem_wait(&this->semSlave) == 0);
66}
67
68//------------------------------------------------------------------------------
71inline void
73{
74 n_assert(sem_post(&this->semSlave) == 0);
75 n_assert(sem_wait(&this->semMaster) == 0);
76}
77
78} // namespace Linux
79//------------------------------------------------------------------------------
A thread barrier for 2 threads using semaphores.
Definition linuxrendezvous.h:18
LinuxRendezvous()
constructor
Definition linuxrendezvous.h:39
sem_t semSlave
Definition linuxrendezvous.h:32
~LinuxRendezvous()
destructor
Definition linuxrendezvous.h:52
void MasterArrive()
call for "master" thread
Definition linuxrendezvous.h:62
sem_t semMaster
Definition linuxrendezvous.h:31
void SlaveArrive()
call for "slave" thread
Definition linuxrendezvous.h:72
#define n_assert(exp)
Definition debug.h:50
Definition linuxcompletioncounter.h:15
A semaphore is an inter-GPU queue synchronization primitive.