*** empty log message ***

git-svn-id: https://ceph.svn.sf.net/svnroot/ceph@196 29311d96-e01e-0410-9327-a35deaab8ce9
This commit is contained in:
sage 2005-05-03 17:31:45 +00:00
parent 5176d3e35b
commit ff281d3c94
7 changed files with 92 additions and 48 deletions

View File

@ -233,8 +233,7 @@ int ceph_fuse_main(Client *c, int argc, char *argv[])
newargv[newargc++] = "-f";
// copy rest of cmdline
//for (int argctr = 1; argctr < argc; argctr++) newargv[newargc++] = argv[argctr];
newargv[newargc++] = "t";
for (int argctr = 1; argctr < argc; argctr++) newargv[newargc++] = argv[argctr];
// go fuse go
cout << "ok, calling fuse_main" << endl;

38
ceph/common/Cond.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef _Cond_Posix_
#define _Cond_Posix_
#include "Mutex.h"
#include <pthread.h>
#include <cassert>
class Cond
{
mutable pthread_cond_t C;
void operator=(Cond &C) {}
Cond( const Cond &C ) {}
public:
Cond() {
pthread_cond_init(&C,NULL);
}
virtual ~Cond() {
pthread_cond_destroy(&C);
}
int Wait(Mutex &mutex) {
int r = pthread_cond_wait(&C, &mutex.M);
return r;
}
int Signal() {
int r = pthread_cond_signal(&C);
return r;
}
};
#endif // !_Cond_Posix_

View File

@ -19,8 +19,6 @@ class Mutex
void operator=(Mutex &M) {}
Mutex( const Mutex &M ) {}
bool locked;
public:
Mutex()
@ -28,9 +26,8 @@ class Mutex
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr,PTHREAD_MUTEX_RECURSIVE);
cout << "mutex init = " << pthread_mutex_init(&M,NULL) << endl;
cout << this << " mutex init = " << pthread_mutex_init(&M,NULL) << endl;
pthread_mutexattr_destroy(&attr);
locked = false;
}
virtual ~Mutex()
@ -38,9 +35,7 @@ class Mutex
int Lock() {
int r = pthread_mutex_lock(&M);
cout << pthread_self() << " lock = " << r << endl;
assert(!locked);
locked = true;
cout << this << " " << pthread_self() << " lock = " << r << endl;
return r;
}
@ -49,12 +44,12 @@ class Mutex
int Unlock()
{
assert(locked);
locked = false;
int r = pthread_mutex_unlock(&M);
cout << pthread_self() << " unlock = " << r << endl;
cout << this << " " << pthread_self() << " unlock = " << r << endl;
return r;
}
friend class Cond;
};
#endif // !_Mutex_Posix_

View File

@ -10,7 +10,7 @@ using namespace std;
#undef dout
#define dout(l) if (l<=g_conf.debug) cout << "serializer: "
#define DEBUGLVL 13 // debug level of output
#define DEBUGLVL 1 // debug level of output
// ---------
// incoming messages
@ -22,11 +22,11 @@ void CheesySerializer::dispatch(Message *m)
lock.Lock();
// was i expecting it?
if (call_sem.count(pcid)) {
if (call_cond.count(pcid)) {
// yes, this is a reply to a pending call.
dout(DEBUGLVL) << "dispatch got reply for " << pcid << " " << m << endl;
call_reply[pcid] = m; // set reply
int r = call_sem[pcid]->Post();
int r = call_cond[pcid]->Signal();
//cout << "post = " << r << endl;
lock.Unlock();
} else {
@ -53,8 +53,7 @@ Message *CheesySerializer::sendrecv(Message *m, msg_addr_t dest, int port)
{
int fromport = 0;
static Semaphore stsem;
Semaphore *sem = &stsem;//new Semaphore();
Cond *cond = new Cond();
// make up a pcid that is unique (to me!)
/* NOTE: since request+replies are matched up on pcid's alone, it means that
@ -66,14 +65,14 @@ Message *CheesySerializer::sendrecv(Message *m, msg_addr_t dest, int port)
long pcid = ++last_pcid;
m->set_pcid(pcid);
lock.Lock();
dout(DEBUGLVL) << "sendrecv sending " << m << " on pcid " << pcid << endl;
// add call records
lock.Lock();
assert(call_sem.count(pcid) == 0); // pcid should be UNIQUE
call_sem[pcid] = sem;
assert(call_cond.count(pcid) == 0); // pcid should be UNIQUE
call_cond[pcid] = cond;
call_reply[pcid] = 0; // no reply yet
lock.Unlock();
// send
messenger->send_message(m, dest, port, fromport);
@ -81,19 +80,20 @@ Message *CheesySerializer::sendrecv(Message *m, msg_addr_t dest, int port)
// wait
dout(DEBUGLVL) << "sendrecv waiting for reply on pcid " << pcid << endl;
//cout << "wait start, value = " << sem->Value() << endl;
sem->Wait();
cond->Wait(lock);
// pick up reply
lock.Lock();
Message *reply = call_reply[pcid];
assert(reply);
call_reply.erase(pcid); // remove from call map
call_sem.erase(pcid);
lock.Unlock();
call_cond.erase(pcid);
dout(DEBUGLVL) << "sendrecv got reply " << reply << " on pcid " << pcid << endl;
//delete sem;
lock.Unlock();
return reply;
}

View File

@ -6,7 +6,7 @@
#include "Messenger.h"
#include "Semaphore.h"
#include "Cond.h"
#include "Mutex.h"
#include <map>
@ -20,7 +20,7 @@ class CheesySerializer : public Messenger,
Messenger *messenger; // this is how i communicate
Mutex lock; // protect call_sem, call_reply
map<long, Semaphore*> call_sem;
map<long, Cond*> call_cond;
map<long, Message*> call_reply;
public:

View File

@ -19,7 +19,7 @@
using namespace std;
#include "Semaphore.h"
#include "Cond.h"
#include "Mutex.h"
#include <pthread.h>
@ -33,8 +33,8 @@ hash_map<int, Logger*> loggers;
LogType fakemsg_logtype;
Mutex lock;
Semaphore sem;
Semaphore shutdownsem;
Cond cond;
bool awake = false;
bool shutdown = false;
pthread_t thread_id;
@ -43,17 +43,20 @@ void *fakemessenger_thread(void *ptr)
{
dout(1) << "thread start" << endl;
lock.Lock();
while (1) {
dout(1) << "thread waiting" << endl;
awake = false;
sem.Wait();
cond.Wait(lock);
awake = true;
dout(1) << "thread woke up" << endl;
if (shutdown) break;
fakemessenger_do_loop();
}
lock.Unlock();
dout(1) << "thread finish (i woke up but no messages, bye)" << endl;
shutdownsem.Post();
}
@ -62,9 +65,15 @@ void fakemessenger_startthread() {
}
void fakemessenger_stopthread() {
cout << "fakemessenger_stopthread setting stop flag" << endl;
lock.Lock();
shutdown = true;
sem.Post();
shutdownsem.Wait();
lock.Unlock();
cond.Signal();
cout << "fakemessenger_stopthread waiting" << endl;
void *ptr;
pthread_join(thread_id, &ptr);
}
@ -81,8 +90,6 @@ int fakemessenger_do_loop()
dout(11) << "do_loop top" << endl;
lock.Lock();
map<int, FakeMessenger*>::iterator it = directory.begin();
while (it != directory.end()) {
Message *m = it->second->get_message();
@ -111,24 +118,20 @@ int fakemessenger_do_loop()
}
}
lock.Unlock();
didone = true;
it->second->dispatch(m);
lock.Unlock();
it->second->dispatch(m);
lock.Lock();
}
it++;
}
lock.Unlock();
if (!didone)
break;
}
dout(1) << "do_loop end (no more messages)." << endl;
return 0;
}
@ -203,14 +206,17 @@ int FakeMessenger::send_message(Message *m, msg_addr_t dest, int port, int fromp
assert(0);
}
// wake up loop?
if (!awake) {
dout(1) << "waking up fakemessenger thread" << endl;
awake = true;
sem.Post();
}
lock.Unlock();
cond.Signal();
} else
lock.Unlock();
lock.Unlock();
}

View File

@ -1,3 +1,9 @@
/*
don't use this.. you probably want a pthread Cond instead!
*/
/////////////////////////////////////////////////////////////////////
// Written by Phillip Sitbon
// Copyright 2003