- adaptepte usleep -> Glib::usleep
- update to glib-2.34 Glib::Threads* (not tested yet, am on a Mac)master
parent
dacbfa9b29
commit
bccde4f726
|
@ -12,38 +12,38 @@ Buffer::~Buffer()
|
||||||
void Buffer::set(frame_t data)
|
void Buffer::set(frame_t data)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Threads::Mutex::Lock lock(mutex_);
|
||||||
frame = data;
|
frame = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::set_id(std::string _id)
|
void Buffer::set_id(std::string _id)
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Threads::Mutex::Lock lock(mutex_);
|
||||||
id = _id;
|
id = _id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffer::set_selected(bool _selected)
|
void Buffer::set_selected(bool _selected)
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Threads::Mutex::Lock lock(mutex_);
|
||||||
selected = _selected;
|
selected = _selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
frame_t Buffer::get()
|
frame_t Buffer::get()
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Threads::Mutex::Lock lock(mutex_);
|
||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Buffer::get_id()
|
std::string Buffer::get_id()
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Threads::Mutex::Lock lock(mutex_);
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Buffer::get_selected()
|
bool Buffer::get_selected()
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Threads::Mutex::Lock lock(mutex_);
|
||||||
return selected;
|
return selected;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,6 @@ class Buffer : public sigc::trackable
|
||||||
|
|
||||||
bool selected;
|
bool selected;
|
||||||
|
|
||||||
Glib::Mutex mutex_;
|
Glib::Threads::Mutex mutex_;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,26 +14,26 @@ Buffers::Buffers(int _bufnum)
|
||||||
|
|
||||||
Buffers::~Buffers()
|
Buffers::~Buffers()
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Threads::Mutex::Lock lock(mutex_);
|
||||||
buffers.clear();
|
buffers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer* Buffers::get(int index)
|
Buffer* Buffers::get(int index)
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Threads::Mutex::Lock lock(mutex_);
|
||||||
return buffers[index];
|
return buffers[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffers::add()
|
void Buffers::add()
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Threads::Mutex::Lock lock(mutex_);
|
||||||
id += "1";
|
id += "1";
|
||||||
buffers.push_back( new Buffer( id ) );
|
buffers.push_back( new Buffer( id ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void Buffers::remove(std::string _id)
|
void Buffers::remove(std::string _id)
|
||||||
{
|
{
|
||||||
Glib::Mutex::Lock lock(mutex_);
|
Glib::Threads::Mutex::Lock lock(mutex_);
|
||||||
int size = buffers.size();
|
int size = buffers.size();
|
||||||
for( int i = 0; i < size; i++ )
|
for( int i = 0; i < size; i++ )
|
||||||
{
|
{
|
||||||
|
|
|
@ -38,7 +38,7 @@ class Buffers : public sigc::trackable
|
||||||
private:
|
private:
|
||||||
vector<Buffer*> buffers;
|
vector<Buffer*> buffers;
|
||||||
std::string id;
|
std::string id;
|
||||||
Glib::Mutex mutex_;
|
Glib::Threads::Mutex mutex_;
|
||||||
std::string selected_buffer;
|
std::string selected_buffer;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
#include "Buffer.h"
|
#include "Buffer.h"
|
||||||
#include "Buffers.h"
|
#include "Buffers.h"
|
||||||
|
|
||||||
#define NUMBUFS 100
|
|
||||||
#define NUMTHREADS 20
|
#define NUMTHREADS 20
|
||||||
#define USECS 1000
|
#define USECS 1000
|
||||||
|
|
||||||
|
@ -25,7 +24,7 @@ void writer(void);
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
srand( time(NULL) );
|
srand( time(NULL) );
|
||||||
Glib::thread_init();
|
Glib::init();
|
||||||
|
|
||||||
// our main loop with support for signals and all that jazz
|
// our main loop with support for signals and all that jazz
|
||||||
//Glib::RefPtr<Glib::MainLoop> Main = Glib::MainLoop::create();
|
//Glib::RefPtr<Glib::MainLoop> Main = Glib::MainLoop::create();
|
||||||
|
@ -37,8 +36,8 @@ int main(void)
|
||||||
|
|
||||||
for(int i = 0; i < NUMTHREADS; i++)
|
for(int i = 0; i < NUMTHREADS; i++)
|
||||||
{
|
{
|
||||||
readers.push_back( Glib::Thread::create( sigc::ptr_fun( &reader), false ) );
|
readers.push_back( Glib::Threads::Thread::create( sigc::ptr_fun( &reader), false ) );
|
||||||
writers.push_back( Glib::Thread::create( sigc::ptr_fun( &writer), false ) );
|
writers.push_back( Glib::Threads::Thread::create( sigc::ptr_fun( &writer), false ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
//Main->run();
|
//Main->run();
|
||||||
|
@ -61,7 +60,7 @@ int main(void)
|
||||||
cout << frame.segments[i].r;
|
cout << frame.segments[i].r;
|
||||||
cout << endl << endl;
|
cout << endl << endl;
|
||||||
}
|
}
|
||||||
usleep( 10000 );
|
Glib::usleep( 10000 );
|
||||||
}//*/
|
}//*/
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -77,7 +76,7 @@ void reader(void)
|
||||||
bufnum = rand()%NUMBUFS;
|
bufnum = rand()%NUMBUFS;
|
||||||
frame = buffers->get(bufnum)->get();
|
frame = buffers->get(bufnum)->get();
|
||||||
// cout << "read " << bufnum << endl;
|
// cout << "read " << bufnum << endl;
|
||||||
usleep( rand()%USECS );
|
Glib::usleep( rand()%USECS );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,6 +105,6 @@ void writer(void)
|
||||||
|
|
||||||
buffers->get(bufnum)->set( frame );
|
buffers->get(bufnum)->set( frame );
|
||||||
// cout << "wrote " << bufnum << endl;
|
// cout << "wrote " << bufnum << endl;
|
||||||
usleep( rand()%USECS );
|
Glib::usleep( rand()%USECS );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue