Changeset 1485:3a149151a9cd


Ignore:
Timestamp:
08/29/10 14:59:23 (18 months ago)
Author:
niam
Branch:
default
Message:

[pc::sync] acquire returns false if the lock was not acquired within given timeout

Location:
sources
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • sources/examples/pc_process/test.cc

    r1472 r1485  
    4848        cout << endl << memory << ": " << tools::time::now() << endl, cout.flush(); 
    4949    } dodo_catch (exception::basic *e)   { 
    50         cout << (dodo::string)*e << e->line << endl, cout.flush(); 
     50        cout << (dodo::string)*e << " " << e->file << ":" << e->line << endl, cout.flush(); 
    5151    } 
    5252 
  • sources/include/libdodo/exceptionBasic.h

    r1480 r1485  
    104104            MODULE_PCSYNCTHREAD, 
    105105            MODULE_PCSYNCPROCESS, 
     106            MODULE_PCSYNCDATAOBJECT, 
    106107            MODULE_PCNOTIFICATIONTHREAD, 
    107108            MODULE_GRAPHICSIMAGE, 
  • sources/include/libdodo/pc.h

    r1468 r1485  
    4040#include <libdodo/pcExecutionSchedulerEx.h> 
    4141#include <libdodo/pcExecutionWorkqueue.h> 
     42#include <libdodo/pcNotificationThread.h> 
     43#include <libdodo/pcNotificationThreadEx.h> 
    4244#include <libdodo/pcSyncDataObject.h> 
     45#include <libdodo/pcSyncDataObjectEx.h> 
    4346#include <libdodo/pcSyncProcess.h> 
    4447#include <libdodo/pcSyncProcessEx.h> 
  • sources/include/libdodo/pcNotificationThreadEx.h

    r1479 r1485  
    3939        namespace notification { 
    4040            /** 
    41              * libdodo defined errors 
    42              */ 
    43             enum threadExR { 
    44                 THREADEX_CANNOTLOCK 
    45             }; 
    46  
    47             /** 
    48              * explanations for libdodo defined errors 
    49              */ 
    50 #define PCNOTIFICATIONTHREADEX_CANNOTLOCK_STR      "Item is currently locked, timeout exhousted" 
    51  
    52             /** 
    5341             * IDs of functions where exception might be thrown 
    5442             */ 
  • sources/include/libdodo/pcSyncDataObject.h

    r1439 r1485  
    7575                     * @param timeout defines wait timeout for unlock in microseconds 
    7676                     * @note if timeout is 0 it will wait infinitely 
     77                     * raises an exception if lock was not acquired within given timeout 
    7778                     */ 
    7879                    virtual void *acquire(unsigned long timeout = 0); 
  • sources/include/libdodo/pcSyncProcess.h

    r1439 r1485  
    7171                /** 
    7272                 * lock 
     73                 * @return false if lock was not acquired within given timeout 
    7374                 * @param timeout defines wait timeout for unlock in microseconds 
    7475                 * @note if timeout is 0 it will wait infinitely 
    7576                 */ 
    76                 virtual void acquire(unsigned long timeout = 0); 
     77                virtual bool acquire(unsigned long timeout = 0); 
    7778 
    7879                /** 
  • sources/include/libdodo/pcSyncProcessEx.h

    r1439 r1485  
    3939        namespace sync { 
    4040            /** 
    41              * libdodo defined errors 
    42              */ 
    43             enum processExR { 
    44                 PROCESSEX_CANNOTLOCK, 
    45             }; 
    46  
    47             /** 
    48              * explanations for libdodo defined errors 
    49              */ 
    50 #define PCSYNCPROCESSEX_CANNOTLOCK_STR      "Item is currently locked, timeout exhousted" 
    51  
    52             /** 
    5341             * IDs of functions where exception might be thrown 
    5442             */ 
  • sources/include/libdodo/pcSyncProtector.h

    r1439 r1485  
    5050                /** 
    5151                 * lock 
     52                 * @return false if lock was not acquired within given timeout 
    5253                 * @param timeout defines wait timeout for unlock in microseconds 
    5354                 * @note if timeout is 0 it will wait infinitely 
    5455                 */ 
    55                 virtual void acquire(unsigned long timeout) = 0; 
     56                virtual bool acquire(unsigned long timeout) = 0; 
    5657 
    5758                /** 
  • sources/include/libdodo/pcSyncThread.h

    r1479 r1485  
    7171                /** 
    7272                 * lock 
     73                 * @return false if lock was not acquired within given timeout 
    7374                 * @param timeout defines wait timeout for unlock in microseconds 
    7475                 * @note if timeout is 0 it will wait infinitely 
    7576                 */ 
    76                 virtual void acquire(unsigned long timeout = 0); 
     77                virtual bool acquire(unsigned long timeout = 0); 
    7778 
    7879                /** 
  • sources/include/libdodo/pcSyncThreadEx.h

    r1439 r1485  
    3939        namespace sync { 
    4040            /** 
    41              * libdodo defined errors 
    42              */ 
    43             enum threadExR { 
    44                 THREADEX_CANNOTLOCK 
    45             }; 
    46  
    47             /** 
    48              * explanations for libdodo defined errors 
    49              */ 
    50 #define PCSYNCTHREADEX_CANNOTLOCK_STR      "Item is currently locked, timeout exhousted" 
    51  
    52             /** 
    5341             * IDs of functions where exception might be thrown 
    5442             */ 
  • sources/src/pcSyncDataObject.cc

    r1439 r1485  
    3131 
    3232#include <libdodo/pcSyncDataObject.h> 
     33#include <libdodo/pcSyncDataObjectEx.h> 
    3334#include <libdodo/pcSyncProtector.h> 
    3435#include <libdodo/pcSyncStack.h> 
     
    7273object::acquire(unsigned long timeout) 
    7374{ 
    74     lock.acquire(timeout); 
     75    if (!lock.acquire(timeout)) 
     76        dodo_throw exception::basic(exception::MODULE_PCSYNCDATAOBJECT, DATAOBJECTEX_ACQUIRE, exception::ERRNO_LIBDODO, DATAOBJECTEX_CANNOTLOCK, PCSYNCDATAOBJECTEX_CANNOTLOCK_STR, __LINE__, __FILE__); 
     77 
    7578    return data; 
    7679} 
  • sources/src/pcSyncProcess.cc

    r1477 r1485  
    213213//------------------------------------------------------------------- 
    214214 
    215 void 
     215bool 
    216216process::acquire(unsigned long microseconds) 
    217217{ 
     
    221221        ++recursive; 
    222222 
    223         return; 
     223        return true; 
    224224    } 
    225225 
     
    235235        if (semtimedop(lock->keeper, lock->operations, 1, &ts) != 0) { 
    236236            if (errno == EAGAIN) 
    237                 dodo_throw exception::basic(exception::MODULE_PCSYNCPROCESS, PROCESSEX_ACQUIRE, exception::ERRNO_LIBDODO, PROCESSEX_CANNOTLOCK, PCSYNCPROCESSEX_CANNOTLOCK_STR, __LINE__, __FILE__); 
     237                return false; 
    238238            else 
    239239                dodo_throw exception::basic(exception::MODULE_PCSYNCPROCESS, PROCESSEX_ACQUIRE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     
    258258        if (sem_timedwait(lock->keeper, &ts) != 0) { 
    259259            if (errno == ETIMEDOUT) 
    260                 dodo_throw exception::basic(exception::MODULE_PCSYNCPROCESS, PROCESSEX_ACQUIRE, exception::ERRNO_LIBDODO, PROCESSEX_CANNOTLOCK, PCSYNCPROCESSEX_CANNOTLOCK_STR, __LINE__, __FILE__); 
     260                return false; 
    261261            else 
    262262                dodo_throw exception::basic(exception::MODULE_PCSYNCPROCESS, PROCESSEX_ACQUIRE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     
    267267    current = pid; 
    268268    recursive = 0; 
     269 
     270    return true; 
    269271} 
    270272 
  • sources/src/pcSyncThread.cc

    r1479 r1485  
    105105//------------------------------------------------------------------- 
    106106 
    107 void 
     107bool 
    108108thread::acquire(unsigned long microseconds) 
    109109{ 
     
    128128        if (errno != 0) { 
    129129            if (errno == ETIMEDOUT) 
    130                 dodo_throw exception::basic(exception::MODULE_PCSYNCTHREAD, THREADEX_ACQUIRE, exception::ERRNO_ERRNO, THREADEX_CANNOTLOCK, PCSYNCTHREADEX_CANNOTLOCK_STR, __LINE__, __FILE__); 
     130                return false; 
    131131            else 
    132132                dodo_throw exception::basic(exception::MODULE_PCSYNCTHREAD, THREADEX_ACQUIRE, exception::ERRNO_ERRNO, errno, strerror(errno), __LINE__, __FILE__); 
     
    134134    } 
    135135#endif 
     136 
     137    return true; 
    136138} 
    137139 
Note: See TracChangeset for help on using the changeset viewer.