lv2 phase 2 fixups
[goodguy/history.git] / cinelerra-5.1 / cinelerra / forkbase.C
index 174019ddd6c27f1d07c604b6c08200bfc8103650..5886424dd7dd1b1a7977b93530dab89fc9d30151 100644 (file)
@@ -64,13 +64,6 @@ int ForkChild::is_running()
        return !ppid || !kill(ppid, 0) ? 1 : 0;
 }
 
-int ForkChild::child_iteration()
-{
-       int ret = read_child(100);
-       if( ret <= 0 ) return ret;
-       return handle_child();
-}
-
 void ForkParent::start_child()
 {
        lock("ForkParent::new_child");
@@ -94,7 +87,7 @@ void ForkParent::start_child()
 // Return -1 if the parent is dead
 // Return  0 if timeout
 // Return  1 if success
-int ForkBase::read_timeout(int ms, int fd, void *data, int bytes)
+int ForkBase::read_timeout(int64_t usec, int fd, void *data, int bytes)
 {
        fd_set rfds;
        struct timeval timeout_struct;
@@ -102,8 +95,8 @@ int ForkBase::read_timeout(int ms, int fd, void *data, int bytes)
        uint8_t *bp = (uint8_t *)data;
 
        while( bytes_read < bytes ) {
-               timeout_struct.tv_sec = ms / 1000;
-               timeout_struct.tv_usec = (ms % 1000) * 1000;
+               timeout_struct.tv_sec = usec / 1000000;
+               timeout_struct.tv_usec = usec % 1000000;
                FD_ZERO(&rfds);
                FD_SET(fd, &rfds);
                int result = select(fd+1, &rfds, 0, 0, &timeout_struct);
@@ -126,10 +119,10 @@ int ForkBase::is_running()
        return !pid || !kill(pid, 0) ? 1 : 0;
 }
 
-int ForkBase::read_parent(int ms)
+int ForkBase::read_parent(int64_t usec)
 {
        token_bfr_t bfr;
-       int ret = read_timeout(ms, parent_fd, &bfr, sizeof(bfr));
+       int ret = read_timeout(usec, parent_fd, &bfr, sizeof(bfr));
        if( ret > 0 ) {
                parent_token = bfr.token;
                parent_bytes = bfr.bytes;
@@ -138,7 +131,7 @@ int ForkBase::read_parent(int ms)
                        parent_data = new uint8_t[parent_allocated = parent_bytes];
                }
                if( parent_bytes ) {
-                       ret = read_timeout(1000, parent_fd, parent_data, parent_bytes);
+                       ret = read_timeout(1000000, parent_fd, parent_data, parent_bytes);
                        if( !ret ) {
                                printf("read_parent timeout: %d\n", parent_fd);
                                ret = -1;
@@ -148,10 +141,10 @@ int ForkBase::read_parent(int ms)
        return ret;
 }
 
-int ForkBase::read_child(int ms)
+int ForkBase::read_child(int64_t usec)
 {
        token_bfr_t bfr;
-       int ret = read_timeout(ms, child_fd, &bfr, sizeof(bfr));
+       int ret = read_timeout(usec, child_fd, &bfr, sizeof(bfr));
        if( ret > 0 ) {
                child_token = bfr.token;
                child_bytes = bfr.bytes;
@@ -160,7 +153,7 @@ int ForkBase::read_child(int ms)
                        child_data = new uint8_t[child_allocated = child_bytes];
                }
                if( child_bytes ) {
-                       ret = read_timeout(1000, child_fd, child_data, child_bytes);
+                       ret = read_timeout(1000000, child_fd, child_data, child_bytes);
                        if( !ret ) {
                                printf("read_child timeout: %d\n", child_fd);
                                ret = -1;
@@ -205,23 +198,17 @@ int ForkBase::send_child(int64_t token, const void *data, int bytes)
 
 ForkChild::ForkChild()
 {
-       done = 0;
+       parent_done = 0;
 }
 
 ForkChild::~ForkChild()
 {
 }
 
-int ForkChild::handle_child()
-{
-       printf("ForkChild::handle_child %d\n", __LINE__);
-       return 0;
-}
-
 ForkParent::ForkParent()
  : Thread(1, 0, 0)
 {
-       done = -1;
+       parent_done = -1;
 }
 
 ForkParent::~ForkParent()
@@ -253,7 +240,7 @@ int ForkParent::handle_parent()
 
 void ForkParent::start()
 {
-       done = 0;
+       parent_done = 0;
        Thread::start();
 }
 
@@ -270,7 +257,7 @@ void ForkParent::stop()
 
 void ForkParent::run()
 {
-       while( !done && parent_iteration() >= 0 );
-       done = 1;
+       while( !parent_done && parent_iteration() >= 0 );
+       parent_done = 1;
 }