RflySimSDK v3.05
RflySimSDK说明文档
载入中...
搜索中...
未找到
vrpn_PeerMutex类 参考

#include <vrpn_Mutex.h>

+ vrpn_PeerMutex 的协作图:

struct  mutexCallback
 
struct  peerData
 

Public 成员函数

 vrpn_PeerMutex (const char *name, int port, const char *NICaddress=NULL)
 This constructor opens a new connection/port for the mutex.
 
 ~vrpn_PeerMutex (void)
 If isHeldLocally(), calls release().
 
vrpn_bool isAvailable (void) const
 
vrpn_bool isHeldLocally (void) const
 
vrpn_bool isHeldRemotely (void) const
 
int numPeers (void) const
 
void mainloop (void)
 
void request (void)
 
void release (void)
 
vrpn_bool addPeer (const char *stationName)
 Takes a VRPN station name of the form "<host>:<port>".
 
vrpn_bool addRequestGrantedCallback (void *userdata, int(*)(void *))
 These callbacks are triggered when OUR request is granted.
 
vrpn_bool addRequestDeniedCallback (void *userdata, int(*)(void *))
 These callbacks are triggered when OUR request is denied.
 
vrpn_bool addTakeCallback (void *userdata, int(*)(void *))
 
vrpn_bool addReleaseCallback (void *userdata, int(*)(void *))
 

Protected 类型

enum  state { OURS , REQUESTING , AVAILABLE , HELD_REMOTELY }
 

Protected 成员函数

void sendRequest (vrpn_Connection *)
 
void sendRelease (vrpn_Connection *)
 
void sendGrantRequest (vrpn_Connection *, vrpn_uint32 IPnumber, vrpn_uint32 PortNumber)
 
void sendDenyRequest (vrpn_Connection *, vrpn_uint32 IPnumber, vrpn_uint32 PortNumber)
 
void triggerGrantCallbacks (void)
 
void triggerDenyCallbacks (void)
 
void triggerTakeCallbacks (void)
 
void triggerReleaseCallbacks (void)
 
void checkGrantMutex (void)
 
void init (const char *name)
 
 vrpn_PeerMutex (const char *name, vrpn_Connection *c)
 

静态 Protected 成员函数

static int VRPN_CALLBACK handle_request (void *, vrpn_HANDLERPARAM)
 
static int VRPN_CALLBACK handle_release (void *, vrpn_HANDLERPARAM)
 
static int VRPN_CALLBACK handle_grantRequest (void *, vrpn_HANDLERPARAM)
 
static int VRPN_CALLBACK handle_denyRequest (void *, vrpn_HANDLERPARAM)
 
static int VRPN_CALLBACK handle_losePeer (void *, vrpn_HANDLERPARAM)
 

Protected 属性

char * d_mutexName
 
state d_state
 
int d_numPeersGrantingLock
 
vrpn_Connectiond_server
 Receive on this connection.
 
vrpn_Connection ** d_peer
 Send on these connections to other Mutex's well-known-ports.
 
int d_numPeers
 
int d_numConnectionsAllocated
 Dynamic array size for d_peer and d_peerGrantedLock.
 
vrpn_uint32 d_myIP
 
vrpn_uint32 d_myPort
 
vrpn_uint32 d_holderIP
 
vrpn_int32 d_holderPort
 
vrpn_int32 d_myId
 
vrpn_int32 d_request_type
 
vrpn_int32 d_release_type
 
vrpn_int32 d_grantRequest_type
 
vrpn_int32 d_denyRequest_type
 
mutexCallbackd_reqGrantedCB
 
mutexCallbackd_reqDeniedCB
 
mutexCallbackd_takeCB
 
mutexCallbackd_releaseCB
 
peerDatad_peerData
 

详细描述

vrpn_PeerMutex

This class provides distributed mutual exclusion between every instance with the same name for which addPeer() has been called. If a process calls request() when isAvailable() returns true, the mutex will attempt to secure a lock to whatever resource it is governing; either RequestGranted or RequestDenied callbacks will be triggered. If RequestGranted callbacks are triggered, the process has the lock until it explicitly calls release() (and can verify this by checking isHeldLocally()). Once the lock-owner calls release(), Release callbacks at every peer will be triggered.

Like most vrpn classes, the mainloop() must be called frequently.

Note that none of isAvailable(), isHeldLocally(), and isHeldRemotely() are true between when request() is called and either RequestGranted or RequestDenied callbacks are triggered.

构造及析构函数说明

◆ vrpn_PeerMutex() [1/2]

vrpn_PeerMutex ( const char * name,
int port,
const char * NICaddress = NULL )

This constructor opens a new connection/port for the mutex.

◆ ~vrpn_PeerMutex()

◆ vrpn_PeerMutex() [2/2]

vrpn_PeerMutex ( const char * name,
vrpn_Connection * c )
protected

This constructor reuses a SERVER connection for the mutex. BUG BUG BUG - do not use this constructor; it does not reliably resolve race conditions.

成员函数说明

◆ addPeer()

vrpn_bool addPeer ( const char * stationName)

Takes a VRPN station name of the form "<host>:<port>".

◆ addReleaseCallback()

vrpn_bool addReleaseCallback ( void * userdata,
int(*  )(void *) )

These callbacks are triggered when ANY peer releases the mutex.

◆ addRequestDeniedCallback()

vrpn_bool addRequestDeniedCallback ( void * userdata,
int(*  )(void *) )

These callbacks are triggered when OUR request is denied.

◆ addRequestGrantedCallback()

vrpn_bool addRequestGrantedCallback ( void * userdata,
int(*  )(void *) )

These callbacks are triggered when OUR request is granted.

◆ addTakeCallback()

vrpn_bool addTakeCallback ( void * userdata,
int(*  )(void *) )

These callbacks are triggered when ANY peer gets the mutex. (If several peers are competing for the mutex, and the implementation issues multiple "grants", these callbacks will only be triggered once between triggerings of ReleaseCallbacks.)

◆ isAvailable()

vrpn_bool isAvailable ( void ) const

True from when release() is called or we receive a release message from another process until request() is called or we grant the lock to another process in response to its request message.

◆ isHeldLocally()

vrpn_bool isHeldLocally ( void ) const

True from when RequestGranted callbacks are triggered until release() is called.

◆ isHeldRemotely()

vrpn_bool isHeldRemotely ( void ) const

True from when we grant the lock to another process in response to its request message until we receive a release message from another process.

◆ release()

void release ( void )

Release the distributed lock. Does nothing if !isHeldLocally() and there isn't a request pending.

◆ request()

void request ( void )

Request the distributed lock. Does not request the lock if !isAvailable(), instead automatically triggering DeniedCallbacks.

类成员变量说明

◆ d_numConnectionsAllocated

int d_numConnectionsAllocated
protected

Dynamic array size for d_peer and d_peerGrantedLock.

◆ d_numPeersGrantingLock

int d_numPeersGrantingLock
protected

Counts the number of "grants" we've received after issuing a request; when this reaches d_numPeers, the lock is ours.

◆ d_peer

vrpn_Connection** d_peer
protected

Send on these connections to other Mutex's well-known-ports.

◆ d_peerData

peerData* d_peerData
protected

Needed only to clean up when a peer shuts down (mid-request). It isn't currently feasible to have all this data, so instead we abort requests that were interrupted by a shutdown.

◆ d_server

vrpn_Connection* d_server
protected

Receive on this connection.


该类的文档由以下文件生成: