TNB Library
D:
Home
Private
TnbLibrary
TnbInc
TnbExchanger.h
[詳解]
1
#pragma once
13
#include "
TnbSync.h
"
14
15
16
17
namespace
TNB
18
{
19
20
21
36
template
<
typename
TYP>
37
class
CExchangerT
38
{
39
LONG m_lCount;
40
CSyncSemaphore
m_syncSema;
41
CSyncEvent
m_syncEvent1;
42
CSyncEvent
m_syncEvent2;
43
volatile
TYP m_tParam1st;
44
volatile
TYP m_tParam2nd;
45
46
public
:
47
49
CExchangerT
(
void
)
50
: m_lCount(0), m_syncSema(NULL, 2), m_syncEvent1(false, true), m_syncEvent2(false, true)
51
{
52
}
53
61
TYP
Exchange
(
const
TYP& t)
62
{
63
EXCLUSIVE
(&m_syncSema);
64
TYP r;
65
LONG l = ::InterlockedIncrement(&m_lCount);
66
if
( l == 1 )
67
{
68
m_tParam1st = t;
69
m_syncEvent2.
Lock
();
70
m_syncEvent1.
Unlock
();
71
r = m_tParam2nd;
72
}
73
else
74
{
75
m_lCount = 0;
76
m_tParam2nd = t;
77
m_syncEvent2.
Unlock
();
78
m_syncEvent1.
Lock
();
79
r = m_tParam1st;
80
}
81
return
r;
82
}
83
};
84
85
86
87
};
// TNB
TnbSync.h
同期処理関係のヘッダ
TNB::CAbstractSyncHandle::Lock
virtual bool Lock(DWORD dwTime=INFINITE) const
[排他] ロック
Definition:
TnbSync.h:91
TNB::CExchangerT
スレッド間値入れ替えテンプレートクラス.
Definition:
TnbExchanger.h:38
TNB::CExchangerT::CExchangerT
CExchangerT(void)
コンストラクタ
Definition:
TnbExchanger.h:49
TNB::CExchangerT::Exchange
TYP Exchange(const TYP &t)
[取得] 値交換.
Definition:
TnbExchanger.h:61
TNB::CSyncEvent
Event排他管理クラス
Definition:
TnbSync.h:480
TNB::CSyncEvent::Unlock
virtual void Unlock(void) const
[排他] アンロック
Definition:
TnbSync.h:532
TNB::CSyncSemaphore
Semaphore排他管理クラス
Definition:
TnbSync.h:370
EXCLUSIVE
#define EXCLUSIVE(CLS)
簡易排他制御マクロ.
Definition:
TnbSync.h:788
TNB
TNB Library
Definition:
TnbDoxyTitle.txt:2
2022年02月21日(月) 14時13分55秒作成 - TNB Library / 構成:
1.9.3