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);
|
||||
}
|
||||
int main(int argc, char *argv[]) {
|
||||
PIDiagnostics d;
|
||||
piCout << d.receiveBytesPerSec();
|
||||
piSleep(3);
|
||||
piCout << d.receiveBytesPerSec();
|
||||
PIMutex m;
|
||||
m.lock();
|
||||
m.unlock();
|
||||
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;
|
||||
// for (int i = 0; i < 50; ++i)
|
||||
// in << i%10;
|
||||
@@ -51,6 +63,7 @@ int main(int argc, char *argv[]) {
|
||||
// fft.preparePlan(50, PIFFTWf::foReal);
|
||||
// PIVector<complexf> out = fft.calcFFT(in);
|
||||
// piCout << out;
|
||||
|
||||
/*for (int i = 0; i < 16; ++i) {
|
||||
piCout << asize(i, 100);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#define PIINCLUDES_P_H
|
||||
|
||||
|
||||
#include "pibase.h"
|
||||
#include "picout.h"
|
||||
#ifdef WINDOWS
|
||||
# include <stdarg.h>
|
||||
# include <windef.h>
|
||||
|
||||
@@ -140,6 +140,12 @@ public:
|
||||
EVENT2(dataReceivedEvent, const PIString &, from, const PIByteArray &, data)
|
||||
EVENT1(peerConnectedEvent, 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:
|
||||
virtual void dataReceived(const PIString & from, const PIByteArray & data) {;}
|
||||
@@ -196,7 +202,6 @@ private:
|
||||
|
||||
protected:
|
||||
bool inited__; //for internal use
|
||||
PIMutex mc_mutex, eth_mutex, peers_mutex, send_mutex, send_mc_mutex;
|
||||
|
||||
private:
|
||||
PIVector<PIEthernet * > eths_traffic, eths_mcast, eths_bcast;
|
||||
@@ -215,7 +220,8 @@ private:
|
||||
PIMutex read_buffer_mutex;
|
||||
PIQueue<PIByteArray> read_buffer;
|
||||
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 & v) {c.space(); c << "PeerInfo(" << v.name << ", " << v.dist << ", " << v.addresses << ")"; return c;}
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
PRIVATE_DEFINITION_START(PIMutex)
|
||||
#ifdef WINDOWS
|
||||
void *
|
||||
HANDLE
|
||||
#else
|
||||
pthread_mutex_t
|
||||
#endif
|
||||
@@ -66,7 +66,10 @@ PIMutex::~PIMutex() {
|
||||
|
||||
void PIMutex::lock() {
|
||||
#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
|
||||
pthread_mutex_lock(&(PRIVATE->mutex));
|
||||
#endif
|
||||
@@ -76,7 +79,10 @@ void PIMutex::lock() {
|
||||
|
||||
void PIMutex::unlock() {
|
||||
#ifdef WINDOWS
|
||||
ReleaseMutex(PRIVATE->mutex);
|
||||
// BOOL wr =
|
||||
// ReleaseMutex(PRIVATE->mutex);
|
||||
SetEvent(PRIVATE->mutex);
|
||||
// std::cout << (ullong)PRIVATE->mutex << " unlock wr=" << wr << std::endl;
|
||||
#else
|
||||
pthread_mutex_unlock(&(PRIVATE->mutex));
|
||||
#endif
|
||||
@@ -97,6 +103,7 @@ bool PIMutex::tryLock() {
|
||||
|
||||
|
||||
bool PIMutex::isLocked() const {
|
||||
// std::cout << "test " << (ullong)PRIVATE->mutex << std::endl;
|
||||
return locked;
|
||||
}
|
||||
|
||||
@@ -104,7 +111,9 @@ bool PIMutex::isLocked() const {
|
||||
void PIMutex::init() {
|
||||
if (inited_) destroy();
|
||||
#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
|
||||
pthread_mutexattr_t attr;
|
||||
memset(&attr, 0, sizeof(attr));
|
||||
@@ -122,6 +131,7 @@ void PIMutex::init() {
|
||||
void PIMutex::destroy() {
|
||||
if (inited_) {
|
||||
#ifdef WINDOWS
|
||||
// std::cout << "destroy " << (ullong)PRIVATE->mutex << std::endl;
|
||||
if (PRIVATE->mutex) CloseHandle(PRIVATE->mutex);
|
||||
PRIVATE->mutex = 0;
|
||||
#else
|
||||
|
||||
@@ -58,9 +58,9 @@ private:
|
||||
|
||||
void init();
|
||||
void destroy();
|
||||
PRIVATE_DECLARATION
|
||||
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) {
|
||||
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);
|
||||
Remote * r = remotes.value(p_name, 0);
|
||||
if (!r) return;
|
||||
@@ -714,6 +717,7 @@ void Daemon::dataReceived(const PIString & from, const PIByteArray & data) {
|
||||
// piCout << "rec" << data.size();
|
||||
if (data.size() < 4) return;
|
||||
PIMutexLocker ml(remote_mutex);
|
||||
// piCout << "lock in dataReceived";
|
||||
PIByteArray ba(data), rba;
|
||||
Remote * r = remotes.value(from);
|
||||
PIString dir;
|
||||
|
||||
@@ -54,12 +54,6 @@ public:
|
||||
PIString thisDaemonName() const {return selfInfo().name.mid(6);}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user