![]() |
RflySimSDK v3.05
RflySimSDK说明文档
|
#include <vrpn_Mutex.h>
类 | |
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_Connection * | d_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 |
mutexCallback * | d_reqGrantedCB |
mutexCallback * | d_reqDeniedCB |
mutexCallback * | d_takeCB |
mutexCallback * | d_releaseCB |
peerData * | d_peerData |
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 | ( | 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().
|
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.
vrpn_bool addPeer | ( | const char * | stationName | ) |
Takes a VRPN station name of the form "<host>:<port>".
vrpn_bool addReleaseCallback | ( | void * | userdata, |
int(* | )(void *) ) |
These callbacks are triggered when ANY peer releases the mutex.
vrpn_bool addRequestDeniedCallback | ( | void * | userdata, |
int(* | )(void *) ) |
These callbacks are triggered when OUR request is denied.
vrpn_bool addRequestGrantedCallback | ( | void * | userdata, |
int(* | )(void *) ) |
These callbacks are triggered when OUR request is granted.
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.)
vrpn_bool isAvailable | ( | void | ) | const |
vrpn_bool isHeldLocally | ( | void | ) | const |
True from when RequestGranted callbacks are triggered until release() is called.
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.
void release | ( | void | ) |
Release the distributed lock. Does nothing if !isHeldLocally() and there isn't a request pending.
void request | ( | void | ) |
Request the distributed lock. Does not request the lock if !isAvailable(), instead automatically triggering DeniedCallbacks.
|
protected |
Dynamic array size for d_peer and d_peerGrantedLock.
|
protected |
Counts the number of "grants" we've received after issuing a request; when this reaches d_numPeers, the lock is ours.
|
protected |
Send on these connections to other Mutex's well-known-ports.
|
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.
|
protected |
Receive on this connection.