git-svn-id: svn://db.shs.com.ru/pip@429 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
21
main.cpp
21
main.cpp
@@ -40,10 +40,22 @@ int asize(ssize_t s, size_t pid_rsize) {
|
|||||||
return (1 << t);
|
return (1 << t);
|
||||||
}
|
}
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
PIDiagnostics d;
|
PIMutex m;
|
||||||
piCout << d.receiveBytesPerSec();
|
m.lock();
|
||||||
piSleep(3);
|
m.unlock();
|
||||||
piCout << d.receiveBytesPerSec();
|
m.lock();
|
||||||
|
m.unlock();
|
||||||
|
m.lock();
|
||||||
|
// m.lock();
|
||||||
|
// m.lock();
|
||||||
|
// m.lock();
|
||||||
|
piCout << "finish" << m.isLocked();
|
||||||
|
|
||||||
|
// PIDiagnostics d;
|
||||||
|
// piCout << d.receiveBytesPerSec();
|
||||||
|
// piSleep(3);
|
||||||
|
// piCout << d.receiveBytesPerSec();
|
||||||
|
|
||||||
// PIVector<float> in;
|
// PIVector<float> in;
|
||||||
// for (int i = 0; i < 50; ++i)
|
// for (int i = 0; i < 50; ++i)
|
||||||
// in << i%10;
|
// in << i%10;
|
||||||
@@ -51,6 +63,7 @@ int main(int argc, char *argv[]) {
|
|||||||
// fft.preparePlan(50, PIFFTWf::foReal);
|
// fft.preparePlan(50, PIFFTWf::foReal);
|
||||||
// PIVector<complexf> out = fft.calcFFT(in);
|
// PIVector<complexf> out = fft.calcFFT(in);
|
||||||
// piCout << out;
|
// piCout << out;
|
||||||
|
|
||||||
/*for (int i = 0; i < 16; ++i) {
|
/*for (int i = 0; i < 16; ++i) {
|
||||||
piCout << asize(i, 100);
|
piCout << asize(i, 100);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
#define PIINCLUDES_P_H
|
#define PIINCLUDES_P_H
|
||||||
|
|
||||||
|
|
||||||
#include "pibase.h"
|
#include "picout.h"
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
# include <windef.h>
|
# include <windef.h>
|
||||||
|
|||||||
@@ -141,6 +141,12 @@ public:
|
|||||||
EVENT1(peerConnectedEvent, const PIString &, name)
|
EVENT1(peerConnectedEvent, const PIString &, name)
|
||||||
EVENT1(peerDisconnectedEvent, const PIString &, name)
|
EVENT1(peerDisconnectedEvent, const PIString &, name)
|
||||||
|
|
||||||
|
bool lockedEth() const {return eth_mutex.isLocked();}
|
||||||
|
bool lockedPeers() const {return peers_mutex.isLocked();}
|
||||||
|
bool lockedMBcasts() const {return mc_mutex.isLocked();}
|
||||||
|
bool lockedSends() const {return send_mutex.isLocked();}
|
||||||
|
bool lockedMCSends() const {return send_mc_mutex.isLocked();}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void dataReceived(const PIString & from, const PIByteArray & data) {;}
|
virtual void dataReceived(const PIString & from, const PIByteArray & data) {;}
|
||||||
virtual void peerConnected(const PIString & name) {;}
|
virtual void peerConnected(const PIString & name) {;}
|
||||||
@@ -196,7 +202,6 @@ private:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool inited__; //for internal use
|
bool inited__; //for internal use
|
||||||
PIMutex mc_mutex, eth_mutex, peers_mutex, send_mutex, send_mc_mutex;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PIVector<PIEthernet * > eths_traffic, eths_mcast, eths_bcast;
|
PIVector<PIEthernet * > eths_traffic, eths_mcast, eths_bcast;
|
||||||
@@ -215,7 +220,8 @@ private:
|
|||||||
PIMutex read_buffer_mutex;
|
PIMutex read_buffer_mutex;
|
||||||
PIQueue<PIByteArray> read_buffer;
|
PIQueue<PIByteArray> read_buffer;
|
||||||
int read_buffer_size;
|
int read_buffer_size;
|
||||||
};
|
PIMutex mc_mutex, eth_mutex, peers_mutex, send_mutex, send_mc_mutex;
|
||||||
|
};
|
||||||
|
|
||||||
inline PICout operator <<(PICout c, const PIPeer::PeerInfo::Address & v) {c.space(); c << "PeerAddress(" << v.address << ", " << v.netmask << ", " << v.ping << ")"; return c;}
|
inline PICout operator <<(PICout c, const PIPeer::PeerInfo::Address & v) {c.space(); c << "PeerAddress(" << v.address << ", " << v.netmask << ", " << v.ping << ")"; return c;}
|
||||||
inline PICout operator <<(PICout c, const PIPeer::PeerInfo & v) {c.space(); c << "PeerInfo(" << v.name << ", " << v.dist << ", " << v.addresses << ")"; return c;}
|
inline PICout operator <<(PICout c, const PIPeer::PeerInfo & v) {c.space(); c << "PeerInfo(" << v.name << ", " << v.dist << ", " << v.addresses << ")"; return c;}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
|
|
||||||
PRIVATE_DEFINITION_START(PIMutex)
|
PRIVATE_DEFINITION_START(PIMutex)
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
void *
|
HANDLE
|
||||||
#else
|
#else
|
||||||
pthread_mutex_t
|
pthread_mutex_t
|
||||||
#endif
|
#endif
|
||||||
@@ -66,7 +66,10 @@ PIMutex::~PIMutex() {
|
|||||||
|
|
||||||
void PIMutex::lock() {
|
void PIMutex::lock() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
WaitForSingleObject(PRIVATE->mutex, INFINITE);
|
// std::cout << (ullong)PRIVATE->mutex << "locking..." << std::endl;
|
||||||
|
// DWORD wr =
|
||||||
|
WaitForSingleObject(PRIVATE->mutex, INFINITE);
|
||||||
|
// std::cout << (ullong)PRIVATE->mutex << " lock wr=" << wr << std::endl;
|
||||||
#else
|
#else
|
||||||
pthread_mutex_lock(&(PRIVATE->mutex));
|
pthread_mutex_lock(&(PRIVATE->mutex));
|
||||||
#endif
|
#endif
|
||||||
@@ -76,7 +79,10 @@ void PIMutex::lock() {
|
|||||||
|
|
||||||
void PIMutex::unlock() {
|
void PIMutex::unlock() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
ReleaseMutex(PRIVATE->mutex);
|
// BOOL wr =
|
||||||
|
// ReleaseMutex(PRIVATE->mutex);
|
||||||
|
SetEvent(PRIVATE->mutex);
|
||||||
|
// std::cout << (ullong)PRIVATE->mutex << " unlock wr=" << wr << std::endl;
|
||||||
#else
|
#else
|
||||||
pthread_mutex_unlock(&(PRIVATE->mutex));
|
pthread_mutex_unlock(&(PRIVATE->mutex));
|
||||||
#endif
|
#endif
|
||||||
@@ -97,6 +103,7 @@ bool PIMutex::tryLock() {
|
|||||||
|
|
||||||
|
|
||||||
bool PIMutex::isLocked() const {
|
bool PIMutex::isLocked() const {
|
||||||
|
// std::cout << "test " << (ullong)PRIVATE->mutex << std::endl;
|
||||||
return locked;
|
return locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +111,9 @@ bool PIMutex::isLocked() const {
|
|||||||
void PIMutex::init() {
|
void PIMutex::init() {
|
||||||
if (inited_) destroy();
|
if (inited_) destroy();
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
PRIVATE->mutex = CreateMutex(0, false, 0);
|
// PRIVATE->mutex = CreateMutex(NULL, FALSE, NULL);
|
||||||
|
PRIVATE->mutex = CreateEvent(NULL, FALSE, TRUE, NULL);
|
||||||
|
// std::cout << "create " << (ullong)PRIVATE->mutex << std::endl;
|
||||||
#else
|
#else
|
||||||
pthread_mutexattr_t attr;
|
pthread_mutexattr_t attr;
|
||||||
memset(&attr, 0, sizeof(attr));
|
memset(&attr, 0, sizeof(attr));
|
||||||
@@ -122,6 +131,7 @@ void PIMutex::init() {
|
|||||||
void PIMutex::destroy() {
|
void PIMutex::destroy() {
|
||||||
if (inited_) {
|
if (inited_) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
// std::cout << "destroy " << (ullong)PRIVATE->mutex << std::endl;
|
||||||
if (PRIVATE->mutex) CloseHandle(PRIVATE->mutex);
|
if (PRIVATE->mutex) CloseHandle(PRIVATE->mutex);
|
||||||
PRIVATE->mutex = 0;
|
PRIVATE->mutex = 0;
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ private:
|
|||||||
|
|
||||||
void init();
|
void init();
|
||||||
void destroy();
|
void destroy();
|
||||||
PRIVATE_DECLARATION
|
|
||||||
bool inited_;
|
bool inited_;
|
||||||
volatile bool locked;
|
bool locked;
|
||||||
|
PRIVATE_DECLARATION
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -653,6 +653,9 @@ void Daemon::peerDisconnected(const PIString & p_name) {
|
|||||||
|
|
||||||
void Daemon::filesReceived(const PIString & p_name, bool ok) {
|
void Daemon::filesReceived(const PIString & p_name, bool ok) {
|
||||||
piCout << "files received from" << p_name;
|
piCout << "files received from" << p_name;
|
||||||
|
// piCout << "try lock in filesReceived, now mutex is" << remote_mutex.isLocked();
|
||||||
|
// PIMutexLocker ml(remote_mutex);
|
||||||
|
// piCout << "lock reached";
|
||||||
closeFileDialog(p_name, ok);
|
closeFileDialog(p_name, ok);
|
||||||
Remote * r = remotes.value(p_name, 0);
|
Remote * r = remotes.value(p_name, 0);
|
||||||
if (!r) return;
|
if (!r) return;
|
||||||
@@ -714,6 +717,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
|||||||
// piCout << "rec" << data.size();
|
// piCout << "rec" << data.size();
|
||||||
if (data.size() < 4) return;
|
if (data.size() < 4) return;
|
||||||
PIMutexLocker ml(remote_mutex);
|
PIMutexLocker ml(remote_mutex);
|
||||||
|
// piCout << "lock in dataReceived";
|
||||||
PIByteArray ba(data), rba;
|
PIByteArray ba(data), rba;
|
||||||
Remote * r = remotes.value(from);
|
Remote * r = remotes.value(from);
|
||||||
PIString dir;
|
PIString dir;
|
||||||
|
|||||||
@@ -55,12 +55,6 @@ public:
|
|||||||
|
|
||||||
PIScreenTile * tile() const;
|
PIScreenTile * tile() const;
|
||||||
|
|
||||||
bool lockedEth() const {return eth_mutex.isLocked();}
|
|
||||||
bool lockedPeers() const {return peers_mutex.isLocked();}
|
|
||||||
bool lockedMBcasts() const {return mc_mutex.isLocked();}
|
|
||||||
bool lockedSends() const {return send_mutex.isLocked();}
|
|
||||||
bool lockedMCSends() const {return send_mc_mutex.isLocked();}
|
|
||||||
|
|
||||||
FileManager fm;
|
FileManager fm;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
Reference in New Issue
Block a user