Update of /cvsroot/playerstage/code/player/libplayertcp
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12092/libplayertcp
Modified Files:
Tag: release-2-0-patches
playertcp.cc playertcp.h remote_driver.cc
Log Message:
backported fixed playertcp mutex management from HEAD
Index: remote_driver.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayertcp/remote_driver.cc,v
retrieving revision 1.15.4.1
retrieving revision 1.15.4.2
diff -C2 -d -r1.15.4.1 -r1.15.4.2
*** remote_driver.cc 20 Apr 2006 00:11:22 -0000 1.15.4.1
--- remote_driver.cc 11 Dec 2007 19:15:28 -0000 1.15.4.2
***************
*** 141,145 ****
this->sock,
false,
! &this->kill_flag);
PLAYER_MSG0(5,"Adding new TCPRemoteDriver to the PlayerTCP Client
List...Success");
--- 141,146 ----
this->sock,
false,
! &this->kill_flag,
! (this->ptcp->thread == pthread_self()));
PLAYER_MSG0(5,"Adding new TCPRemoteDriver to the PlayerTCP Client
List...Success");
***************
*** 326,330 ****
// Set the delete flag, letting PlayerTCP close the connection and
// clean up.
! this->ptcp->DeleteClient(this->queue);
}
return(0);
--- 327,332 ----
// Set the delete flag, letting PlayerTCP close the connection and
// clean up.
! this->ptcp->DeleteClient(this->queue,
! (this->ptcp->thread == pthread_self()));
}
return(0);
***************
*** 335,342 ****
{
if(this->ptcp->thread == pthread_self())
! this->ptcp->Read(0);
this->ProcessMessages();
if(this->ptcp->thread == pthread_self())
! this->ptcp->Write();
}
--- 337,347 ----
{
if(this->ptcp->thread == pthread_self())
! {
! //this->ptcp->Read(0,true);
! this->ptcp->ReadClient(this->queue);
! }
this->ProcessMessages();
if(this->ptcp->thread == pthread_self())
! this->ptcp->Write(true);
}
Index: playertcp.cc
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayertcp/playertcp.cc,v
retrieving revision 1.48.2.1
retrieving revision 1.48.2.2
diff -C2 -d -r1.48.2.1 -r1.48.2.2
*** playertcp.cc 20 Apr 2006 00:11:22 -0000 1.48.2.1
--- playertcp.cc 11 Dec 2007 19:15:28 -0000 1.48.2.2
***************
*** 29,32 ****
--- 29,34 ----
#include <errno.h>
#include <string.h>
+ #include <stddef.h>
+ #include <time.h>
#include <unistd.h>
#include <fcntl.h>
***************
*** 100,110 ****
this->client_ufds = (struct pollfd*)NULL;
! pthread_mutexattr_t mutex_attr;
! pthread_mutexattr_init(&mutex_attr);
! // TODO: see what happens if recursive mutexes are not available
! #ifdef PTHREAD_MUTEX_RECURSIVE
! pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
! #endif
! pthread_mutex_init(&this->clients_mutex,&mutex_attr);
this->num_listeners = 0;
--- 102,106 ----
this->client_ufds = (struct pollfd*)NULL;
! pthread_mutex_init(&this->clients_mutex,NULL);
this->num_listeners = 0;
***************
*** 170,174 ****
}
- // Should be called with client_mutex locked
MessageQueue*
PlayerTCP::AddClient(struct sockaddr_in* cliaddr,
--- 166,169 ----
***************
*** 177,182 ****
int newsock,
bool send_banner,
! int* kill_flag)
{
unsigned char data[PLAYER_IDENT_STRLEN];
--- 172,181 ----
int newsock,
bool send_banner,
! int* kill_flag,
! bool have_lock)
{
+ if(!have_lock)
+ Lock();
+
unsigned char data[PLAYER_IDENT_STRLEN];
***************
*** 249,252 ****
--- 248,254 ----
j, this->clients[j].port, this->clients[j].fd);
+ if(!have_lock)
+ Unlock();
+
return(this->clients[j].queue);
}
***************
*** 302,306 ****
this->host,
this->listeners[i].port,
! newsock, true, NULL);
num_accepts--;
--- 304,308 ----
this->host,
this->listeners[i].port,
! newsock, true, NULL, false);
num_accepts--;
***************
*** 349,353 ****
int
! PlayerTCP::Read(int timeout)
{
int num_available;
--- 351,355 ----
int
! PlayerTCP::Read(int timeout, bool have_lock)
{
int num_available;
***************
*** 355,368 ****
if(!this->num_clients)
{
! usleep(timeout);
! return(0);
}
! pthread_mutex_lock(&this->clients_mutex);
// Poll for incoming messages
if((num_available = poll(this->client_ufds, this->num_clients, timeout)) <
0)
{
! pthread_mutex_unlock(&this->clients_mutex);
// Got interrupted by a signal; no problem
--- 357,375 ----
if(!this->num_clients)
{
! struct timespec ts;
! ts.tv_sec = timeout / 1000000;
! ts.tv_nsec = (timeout % 1000000) * 1000;
! nanosleep(&ts, NULL);
! return 0;
}
! if(!have_lock)
! Lock();
// Poll for incoming messages
if((num_available = poll(this->client_ufds, this->num_clients, timeout)) <
0)
{
! if(!have_lock)
! Unlock();
// Got interrupted by a signal; no problem
***************
*** 377,381 ****
if(!num_available)
{
! pthread_mutex_unlock(&this->clients_mutex);
return(0);
}
--- 384,389 ----
if(!num_available)
{
! if(!have_lock)
! Unlock();
return(0);
}
***************
*** 404,408 ****
this->DeleteClients();
! pthread_mutex_unlock(&this->clients_mutex);
return(0);
--- 412,417 ----
this->DeleteClients();
! if(!have_lock)
! Unlock();
return(0);
***************
*** 460,465 ****
// Should be called with clients_mutex lock held
void
! PlayerTCP::DeleteClient(MessageQueue* q)
{
// Find the client and mark it for deletion.
int i;
--- 469,476 ----
// Should be called with clients_mutex lock held
void
! PlayerTCP::DeleteClient(MessageQueue* q, bool have_lock)
{
+ if(!have_lock)
+ Lock();
// Find the client and mark it for deletion.
int i;
***************
*** 472,475 ****
--- 483,488 ----
}
}
+ if(!have_lock)
+ Unlock();
}
***************
*** 671,677 ****
int
! PlayerTCP::Write()
{
! pthread_mutex_lock(&this->clients_mutex);
for(int i=0;i<this->num_clients;i++)
--- 684,691 ----
int
! PlayerTCP::Write(bool have_lock)
{
! if(!have_lock)
! Lock();
for(int i=0;i<this->num_clients;i++)
***************
*** 686,690 ****
this->DeleteClients();
! pthread_mutex_unlock(&this->clients_mutex);
return(0);
--- 700,705 ----
this->DeleteClients();
! if(!have_lock)
! Unlock();
return(0);
***************
*** 692,695 ****
--- 707,721 ----
int
+ PlayerTCP::ReadClient(MessageQueue* q)
+ {
+ for(int cli=0; cli < this->num_clients; cli++)
+ {
+ if(this->clients[cli].queue == q)
+ return(ReadClient(cli));
+ }
+ return(-1);
+ }
+
+ int
PlayerTCP::ReadClient(int cli)
{
***************
*** 1232,1233 ****
--- 1258,1271 ----
}
+
+ void
+ PlayerTCP::Lock()
+ {
+ pthread_mutex_lock(&clients_mutex);
+ }
+
+ void
+ PlayerTCP::Unlock()
+ {
+ pthread_mutex_unlock(&clients_mutex);
+ }
Index: playertcp.h
===================================================================
RCS file: /cvsroot/playerstage/code/player/libplayertcp/playertcp.h,v
retrieving revision 1.20.2.1
retrieving revision 1.20.2.2
diff -C2 -d -r1.20.2.1 -r1.20.2.2
*** playertcp.h 20 Apr 2006 00:11:22 -0000 1.20.2.1
--- playertcp.h 11 Dec 2007 19:15:28 -0000 1.20.2.2
***************
*** 120,123 ****
--- 120,126 ----
int decode_readbuffersize;
+ void Lock();
+ void Unlock();
+
public:
PlayerTCP();
***************
*** 132,146 ****
int newsock,
bool send_banner,
! int* kill_flag);
int Accept(int timeout);
void Close(int cli);
int ReadClient(int cli);
! int Read(int timeout);
! int Write();
int WriteClient(int cli);
void DeleteClients();
void ParseBuffer(int cli);
int HandlePlayerMessage(int cli, Message* msg);
! void DeleteClient(MessageQueue* q);
bool Listening(int port);
uint32_t GetHost() {return host;};
--- 135,151 ----
int newsock,
bool send_banner,
! int* kill_flag,
! bool have_lock);
int Accept(int timeout);
void Close(int cli);
int ReadClient(int cli);
! int ReadClient(MessageQueue* q);
! int Read(int timeout, bool have_lock);
! int Write(bool have_lock);
int WriteClient(int cli);
void DeleteClients();
void ParseBuffer(int cli);
int HandlePlayerMessage(int cli, Message* msg);
! void DeleteClient(MessageQueue* q, bool have_lock);
bool Listening(int port);
uint32_t GetHost() {return host;};
-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit