Hi!
On 12.02.2014 19:44, [email protected] wrote:
> Hi!
>> ...
>> +static int get_tst_count()
>> +{
>> +    int res;
>> +    pthread_mutex_lock(&tstcount_mutex);
>> +    res = tst_count;
>> +    pthread_mutex_unlock(&tstcount_mutex);
>> +    return res;
>> +}
>> +
>> +static void cat_file_r(char *filename);
> This is hardly pefromance critical code so we don't need fine grade
> locking as this. What we can do in most of the cases is to take the
> mutext and call the function from tst_res.c, which would lead to much
> simpler code.
>
>> ...
>> +    if (size + 1 >= sizeof(message)) {
>> +            printf("%s: %i: line too long\n", __func__, __LINE__);
>> +            abort();
>> +    }
>> +
>> +    message[size] = '\n';
>> +    message[size + 1] = '\0';
>> +
>> +    pthread_mutex_lock(&tout_mutex);
>> +    fputs(message, T_out);
>> +    pthread_mutex_unlock(&tout_mutex);
>> +
>> +    /*
>> +     * If tst_res() was called with a file, append file contents to the
>> +     * end of last printed result.
>> +     */
>> +    if (fname != NULL)
>> +            cat_file_r(fname);
>> +}
> The same here. I don't like that the code is copied, one copy of messy
> tst_print_r is more than enough. All that should be needed are mutexes
> in the entry points to the ltp library, or do we have real reason not
> to do it this way?
Not really, if performance is not the case it might be simplified 
greatly with the one global lock.
OK, so then what about having tst_res_r.c with just initialization of 
that lock and test.h file with set of macros (may be defined in another 
header along with "once_fun" macro) as follows?

Just tmutex's initializer in tst_res_r.c:
pthread_mutex_t tmutex = PTHREAD_MUTEX_INITIALIZER;

test.h or inclusion of external header:
#ifdef _REENTRANT
extern pthread_mutex_t tmutex;
#define tst_resm(type, fmt, ...) \
         do {                                            \
                 pthread_mutex_lock(&tmutex);            \
                 (tst_resm)(type, fmt, ## __VA_ARGS__);  \
                 pthread_mutex_unlock(&tmutex);          \
         } while(0)

#endif
...
void (tst_resm)(int ttype, char *arg_fmt, ...)
         __attribute__ ((format (printf, 2, 3)));

No changes in tst_res.c, even more we don't need to make tst_res.h

Additionally, we don't need "libltp_r" if we force tests to initialize 
"tmutex".

Best regards,
Alexey

------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to