- adaptepte usleep -> Glib::usleep

- update to glib-2.34 Glib::Threads*

(not tested yet, am on a Mac)
master
Steve Clement 2013-07-15 22:39:25 +02:00
parent dacbfa9b29
commit bccde4f726
5 changed files with 44 additions and 45 deletions

View File

@ -12,38 +12,38 @@ Buffer::~Buffer()
void Buffer::set(frame_t data)
{
{
Glib::Mutex::Lock lock(mutex_);
Glib::Threads::Mutex::Lock lock(mutex_);
frame = data;
}
}
void Buffer::set_id(std::string _id)
{
Glib::Mutex::Lock lock(mutex_);
Glib::Threads::Mutex::Lock lock(mutex_);
id = _id;
}
void Buffer::set_selected(bool _selected)
{
Glib::Mutex::Lock lock(mutex_);
Glib::Threads::Mutex::Lock lock(mutex_);
selected = _selected;
}
frame_t Buffer::get()
{
Glib::Mutex::Lock lock(mutex_);
Glib::Threads::Mutex::Lock lock(mutex_);
return frame;
}
std::string Buffer::get_id()
{
Glib::Mutex::Lock lock(mutex_);
Glib::Threads::Mutex::Lock lock(mutex_);
return id;
}
bool Buffer::get_selected()
{
Glib::Mutex::Lock lock(mutex_);
Glib::Threads::Mutex::Lock lock(mutex_);
return selected;
}

View File

@ -32,6 +32,6 @@ class Buffer : public sigc::trackable
bool selected;
Glib::Mutex mutex_;
Glib::Threads::Mutex mutex_;
};
#endif

View File

@ -14,26 +14,26 @@ Buffers::Buffers(int _bufnum)
Buffers::~Buffers()
{
Glib::Mutex::Lock lock(mutex_);
Glib::Threads::Mutex::Lock lock(mutex_);
buffers.clear();
}
Buffer* Buffers::get(int index)
{
Glib::Mutex::Lock lock(mutex_);
Glib::Threads::Mutex::Lock lock(mutex_);
return buffers[index];
}
void Buffers::add()
{
Glib::Mutex::Lock lock(mutex_);
Glib::Threads::Mutex::Lock lock(mutex_);
id += "1";
buffers.push_back( new Buffer( id ) );
}
void Buffers::remove(std::string _id)
{
Glib::Mutex::Lock lock(mutex_);
Glib::Threads::Mutex::Lock lock(mutex_);
int size = buffers.size();
for( int i = 0; i < size; i++ )
{

View File

@ -38,7 +38,7 @@ class Buffers : public sigc::trackable
private:
vector<Buffer*> buffers;
std::string id;
Glib::Mutex mutex_;
Glib::Threads::Mutex mutex_;
std::string selected_buffer;
};
#endif

View File

@ -9,7 +9,6 @@
#include "Buffer.h"
#include "Buffers.h"
#define NUMBUFS 100
#define NUMTHREADS 20
#define USECS 1000
@ -25,7 +24,7 @@ void writer(void);
int main(void)
{
srand( time(NULL) );
Glib::thread_init();
Glib::init();
// our main loop with support for signals and all that jazz
//Glib::RefPtr<Glib::MainLoop> Main = Glib::MainLoop::create();
@ -37,8 +36,8 @@ int main(void)
for(int i = 0; i < NUMTHREADS; i++)
{
readers.push_back( Glib::Thread::create( sigc::ptr_fun( &reader), false ) );
writers.push_back( Glib::Thread::create( sigc::ptr_fun( &writer), false ) );
readers.push_back( Glib::Threads::Thread::create( sigc::ptr_fun( &reader), false ) );
writers.push_back( Glib::Threads::Thread::create( sigc::ptr_fun( &writer), false ) );
}
//Main->run();
@ -61,7 +60,7 @@ int main(void)
cout << frame.segments[i].r;
cout << endl << endl;
}
usleep( 10000 );
Glib::usleep( 10000 );
}//*/
return 0;
@ -77,7 +76,7 @@ void reader(void)
bufnum = rand()%NUMBUFS;
frame = buffers->get(bufnum)->get();
// cout << "read " << bufnum << endl;
usleep( rand()%USECS );
Glib::usleep( rand()%USECS );
}
}
@ -106,6 +105,6 @@ void writer(void)
buffers->get(bufnum)->set( frame );
// cout << "wrote " << bufnum << endl;
usleep( rand()%USECS );
Glib::usleep( rand()%USECS );
}
}