Commit Graph

3309 Commits

Author SHA1 Message Date
Carsten Haitzler 6abe0b3a94 fix flipped object texture if map enabled AND object happens to be
exactly viewport size.



SVN revision: 52940
2010-10-01 06:22:31 +00:00
Carsten Haitzler 5b45763676 aaaah and map in map clip and more bug fixes...
SVN revision: 52939
2010-10-01 04:46:04 +00:00
Carsten Haitzler 94bfb8fbe6 map in map render bug with gl - fix.
SVN revision: 52936
2010-10-01 03:40:12 +00:00
Carsten Haitzler 0e560f9db2 and make values int so we can have "-1" :)
SVN revision: 52934
2010-09-30 23:23:51 +00:00
Carsten Haitzler 5938bb97f7 found the gl engine flashing white bug with laucnher 3 map test! aaah
gl state bug/assumption. reset state when moving from 1 surface target
to another and then we are all happy. also fix lip geometry issue in
gl when rendering to non-default surf - related.



SVN revision: 52933
2010-09-30 23:20:26 +00:00
Carsten Haitzler 0667809063 xrender engine default--
software_8_x11 default--
software_16_x11 default--



SVN revision: 52867
2010-09-28 22:43:24 +00:00
Carsten Haitzler ae6922fbd0 make sure that at any point if gl barfs... abort then.
SVN revision: 52838
2010-09-28 04:13:28 +00:00
Cedric BAIL 801917565f * evas: fix rendering of object with color (*,*,*,0)
and render_op != BLEND.


SVN revision: 52782
2010-09-26 16:10:59 +00:00
Carsten Haitzler 80197823be make fb engine default on linux too.
SVN revision: 52771
2010-09-26 03:39:18 +00:00
Chidambar 'ilLogict' Zinnoury 15dd911de3 From: Chidambar 'ilLogict' Zinnoury <illogict@online.fr>
Subject: [E-devel] [tentative patch] evas memleak when no callbacks

 I'm seeing some memleaks while using Evas' buffer engine. After
 investigation, it seems that evas_free does nothing and returns
 immediately if the canvas has no callbacks, which is what happens with
 the buffer engine.
 
  The attached patch seems to do the trick.
  
   However, as I don't know that much Evas' internals, I thought it'd be
   better to ask whether it's correct or I'm mistaken before committing.
   
    So please comment.
    


SVN revision: 52769
2010-09-26 02:27:01 +00:00
Carsten Haitzler 9e7bc3f53e wooo overzealous commenting. fix. better now.
SVN revision: 52734
2010-09-25 14:46:10 +00:00
Carsten Haitzler 0e2ec32263 working on debug. doesn't affect anything atm.
SVN revision: 52733
2010-09-25 14:30:02 +00:00
Carsten Haitzler 348f454537 well that improves map a bit! less overdraw! :) and 1 bug fixed. still
1 left.



SVN revision: 52727
2010-09-25 06:19:30 +00:00
Vincent Torri 98247ac8dc formatting
SVN revision: 52714
2010-09-25 04:40:54 +00:00
Lucas De Marchi b5dfed45d8 Use eina_sched_prio_drop()
SVN revision: 52653
2010-09-23 20:40:35 +00:00
Carsten Haitzler ef71a85f2a fix error enum too
SVN revision: 52588
2010-09-22 13:25:17 +00:00
Carsten Haitzler fea985b760 fmting.
SVN revision: 52586
2010-09-22 12:02:35 +00:00
Carsten Haitzler 80e131a443 fmting
SVN revision: 52585
2010-09-22 11:57:19 +00:00
Carsten Haitzler c4d77fea71 docs++
SVN revision: 52584
2010-09-22 11:29:42 +00:00
Carsten Haitzler ea8175d746 fmormatting cleanups
SVN revision: 52583
2010-09-22 11:28:31 +00:00
Carsten Haitzler dddab37368 fmting
SVN revision: 52581
2010-09-22 11:14:25 +00:00
Carsten Haitzler 629916a4ee formatting
SVN revision: 52579
2010-09-22 11:04:32 +00:00
Carsten Haitzler c5977a45dd formatting.
SVN revision: 52578
2010-09-22 11:03:28 +00:00
Carsten Haitzler 2dce035395 warning--, formatting.
SVN revision: 52577
2010-09-22 11:02:19 +00:00
Carsten Haitzler fa813fb8f2 size_t -> int.
really - i prefer it and if we hit the 2gb limit of a signed int for
bytes added to a textblock... thats the day we will need evas 2 :)



SVN revision: 52576
2010-09-22 10:58:44 +00:00
Carsten Haitzler 21ec26bed3 move some simple #define constants to typedefs. api compatible tho.
SVN revision: 52575
2010-09-22 10:52:54 +00:00
Carsten Haitzler 08b5fe088a fmting
SVN revision: 52572
2010-09-22 09:37:18 +00:00
Carsten Haitzler af7910c47b formatting
SVN revision: 52571
2010-09-22 09:28:23 +00:00
Carsten Haitzler f5acc84e67 int -> bool
SVN revision: 52570
2010-09-22 09:19:31 +00:00
Carsten Haitzler 011b2ce822 brutally evil... internally.. but it works. map perspective correct
now in gl engine. hooray for that. one complaint less.



SVN revision: 52566
2010-09-22 06:52:28 +00:00
Tom Hacohen 2d3b0200af Evas textblock: merged changes.
SVN revision: 52544
2010-09-21 15:39:26 +00:00
Iván Briano 68f1a20306 Adding callback for box to be called when a child is added or removed.
Also sets the children_changed flag when changing children list.

    by Otavio Pontes <otavio@profusion.mobi>



SVN revision: 52541
2010-09-21 14:04:28 +00:00
Tom Hacohen ae51c0e16f Evas textblock: Fixed deleting the last visual format in a row of visual formats, for example in '<b>ab</b><tab>cd' the tab wouldn't have gotten erased correctly.
SVN revision: 52540
2010-09-21 13:05:30 +00:00
Lucas De Marchi 71cba7da35 Fix typos
"he->the" where appropriate



SVN revision: 52493
2010-09-20 17:09:13 +00:00
Tom Hacohen 5ba2cc9c6b Evas textblock: Removed the usuned type field from the textblock item.
SVN revision: 52489
2010-09-20 14:14:52 +00:00
Tom Hacohen b98670ab36 Evas textblock: Updated docs.
SVN revision: 52488
2010-09-20 13:04:37 +00:00
Lucas De Marchi 9af1273517 Remove unused field from Evas_Object
Previous commits removed the use of havemap_parent. So, remove the
field as well.

Fix some trailing whitespaces too.



SVN revision: 52486
2010-09-20 10:54:09 +00:00
Tom Hacohen 1f8553de01 Evas textblock: Fixed the mixed usage of a replacement char (e.g * on password textblocks) with formats.
SVN revision: 52485
2010-09-20 10:06:01 +00:00
Tom Hacohen e8c10dbce7 Evas textblock: Added evas_textblock_node_format_remove_pair to remove formats.
SVN revision: 52484
2010-09-20 09:44:48 +00:00
Carsten Haitzler 4b73f639d2 fix booboo
SVN revision: 52482
2010-09-20 01:32:05 +00:00
Gustavo Sverzut Barbieri 9f5dd747ef update README.in with relevant information, fix typos and improve formatting.
* add information about modules "=static" suffix.
 * fix lots of typos spotted by emacs "flyspell-mode".
 * add more spacing and separator lines around sections.



SVN revision: 52477
2010-09-19 21:12:04 +00:00
Gustavo Sverzut Barbieri 200fd80f4e warnings-- on 16bpp and 8bpp
SVN revision: 52472
2010-09-19 20:11:42 +00:00
Carsten Haitzler 1a72827555 warnings--
warnings = 0.



SVN revision: 52449
2010-09-19 02:43:08 +00:00
Carsten Haitzler c54bd4052c warning--
SVN revision: 52448
2010-09-19 02:33:19 +00:00
Carsten Haitzler ca722c0c6a fix clip in simple img obj case
SVN revision: 52446
2010-09-19 02:28:09 +00:00
Carsten Haitzler 2f08e231e5 warning--
SVN revision: 52445
2010-09-19 02:10:09 +00:00
Carsten Haitzler 4faa8c38ca warning--
SVN revision: 52444
2010-09-19 02:04:12 +00:00
Carsten Haitzler 1ca42eee39 warning--
SVN revision: 52443
2010-09-19 02:02:09 +00:00
Carsten Haitzler a8c72076d4 warnings--
SVN revision: 52442
2010-09-19 01:57:19 +00:00
Carsten Haitzler 9cb35948bc warning--
SVN revision: 52441
2010-09-19 01:46:13 +00:00
Carsten Haitzler 16c3803a71 warning--
SVN revision: 52440
2010-09-19 01:42:45 +00:00
Carsten Haitzler c3870d27c0 warning--
SVN revision: 52439
2010-09-19 01:41:46 +00:00
Carsten Haitzler 649509a9c2 warning--
SVN revision: 52438
2010-09-19 01:33:51 +00:00
Carsten Haitzler 857119a1c2 maybe actually fix things correctly eh? -> images load again.
SVN revision: 52435
2010-09-19 01:14:56 +00:00
Carsten Haitzler ccb4dbd91b fix gl stride
SVN revision: 52432
2010-09-19 00:28:58 +00:00
Carsten Haitzler f07a07855a warning--
SVN revision: 52431
2010-09-18 23:45:42 +00:00
Carsten Haitzler 5d15f41500 warning--
SVN revision: 52430
2010-09-18 23:39:30 +00:00
Vincent Torri 89038e3b0c free the main region (leak--)
SVN revision: 52429
2010-09-18 23:17:27 +00:00
Gustavo Sverzut Barbieri d89ebf341b cleanup: internal image information is now unsigned.
There is no meaning in negative values for image loading, marking as
dirty or size, so image internals (cache, entry) were changed to
unsigned, reducing possible errors, particularly with overflow.

engines were converted to the new way, but any 3rd party modules will
still work as they should be using values >= 0 only anyway.

please review.

new cases introduced by "comparison between signed and unsigned" were
fixed in the modules that used cache_entry or Image_Entry dimensions.



SVN revision: 52428
2010-09-18 23:16:25 +00:00
Gustavo Sverzut Barbieri 5dd0eeb7ab cleanup: fb uses unsigned to match linux/fb.h
this removes warnings and keep consistency between system and evas
value signs.



SVN revision: 52427
2010-09-18 23:11:01 +00:00
Gustavo Sverzut Barbieri 19f0eebd27 cleanup: simple clean of "comparison between signed and unsigned errors"
not much to see here, please review but these are simple changes.



SVN revision: 52426
2010-09-18 23:07:31 +00:00
Gustavo Sverzut Barbieri 2640984384 cleanup: evas_macros.h - less comparison between signed and unsigned errors
update macro to do fine with unsigned integers (avoids width and
height getting below 0) and force casts.



SVN revision: 52425
2010-09-18 23:06:22 +00:00
Gustavo Sverzut Barbieri e37c1c7a0a cleanup: fix some "unused" errors from -Wextra.
As we're heading for a release we better remove as much errors as
possible and as the first step I'm removing warnings due unused
parameters, variables and functions. These tend to pollute real errors
spotted by -Wall and clang/llvm.

This does not fixes all, just the clear that could be set to
__UNUSED__, particularly to do (and I'd like some help from the
authors):

 * src/lib/engines/common/evas_font_{draw,query}.c (tasn):
   intl_props is just used while doing BIDI, but also used in other
   #ifdef blocks :-/

 * evas_map_* (raster):
   huge amount of warnings, code is quite confusing and thus I'm not
   touching it. I have no idea whenever the commented blocks or extra
   parameters are intended to be used or no.

 * src/modules/engines/fbevas_fb_main.c (raster?):
   is fb_setvt() to be used? If not do you mind removing it?

 * src/modules/engines/gl_{common,x11} (raster):
   huge amount of warnings, code is quite nested and full of #ifdefs
   that does not help to give a clear picture of what's going on.

 * src/bin/evas_cserve_main.c (raster):
   I could have ignored most of the errors, but is the code correct? I
   mean, there is no unload of images being applied. If you confirm
   none of those warnings are harmful I can flag them as unused.

 * src/lib/engines/common_8 (dottedmag):
   lots of unused functions that were acquired from common_16, they
   are unused and if they will not, then they should be removed.



SVN revision: 52421
2010-09-18 19:17:41 +00:00
Gustavo Sverzut Barbieri a22dac6ea3 Add missing evas_common prefix, avoid symbol redefinition.
soft16 was written as a single engine, thus it was all static/global
and had no EAPI in its functions, but then it was moved into
"src/lib/common_16" and got that, but got no prefix! That could cause
clash with other libraries, so adding such prefix.

soft8 was a copy of 16, thus had the same problems.

the engines were all based on software_x11, thus they defined the same
methods to deal with Xlib, however if you link them all in the same
binary (--enable-MODULE=static), the symbol would be redefined. Rename
symbols according to their module.



SVN revision: 52420
2010-09-18 17:43:13 +00:00
Vincent Torri d128fb54a0 remove debug messages
SVN revision: 52419
2010-09-18 17:31:00 +00:00
Vincent Torri 9acfb01811 Fix shaped windows on Windows. It uses regions.
Advantages:
 * it is the simplest method to implement

Disadvantages:
 * it's slow
 * it does not take into account transparency
 * it does not work with the composite manager (Windows >= Vista)

Layered windows should be used (all the disadvantaged above are
fixed), but i've never succeeded in making them work.

SVN revision: 52416
2010-09-18 17:19:11 +00:00
Carsten Haitzler 6f4d152810 fix actually supporting clip for maps in gl.
SVN revision: 52415
2010-09-18 14:23:20 +00:00
Carsten Haitzler 8df657a51a be less agressive performance-wise but clear up some gl sync issues
that have been lurking.



SVN revision: 52414
2010-09-18 13:49:56 +00:00
Lucas De Marchi 4dcae856ea Fix function call after previous change
Forgot one function call.



SVN revision: 52408
2010-09-18 06:41:04 +00:00
Lucas De Marchi 4db4b59b02 Make _evas_event_havemap_adjust() recursive
Make this function recursive, so it can adjust the coords for all
parent objects. It starts with the grand-grand-grand-...-parent and goes
down until the same object.



SVN revision: 52407
2010-09-18 06:31:41 +00:00
Lucas De Marchi 1a0a9b68f6 Use also map of current object
Do not use only the map of the parent. Apply the obj's map first and
then go to the parent.

+  simple formatting



SVN revision: 52406
2010-09-18 06:31:12 +00:00
Lucas De Marchi a1a69cae0f Remove havemap_parent shortcut
SVN revision: 52405
2010-09-18 06:31:05 +00:00
Lucas De Marchi e478d25f34 Clean unneeded check
SVN revision: 52404
2010-09-18 06:30:59 +00:00
Lucas De Marchi 6f1e1a950e Don't set parmap for the other objects
We are iterating EINA_INLIST_REVERSE_FOREACH(list, obj) in a recursive
function. Don't mark the other objects as havemap_parent if the first
in the list has it.



SVN revision: 52403
2010-09-18 06:30:51 +00:00
Lucas De Marchi bcc9b853ed formatting
SVN revision: 52402
2010-09-18 06:30:45 +00:00
Lucas De Marchi fcd5f99652 clean a bit more
SVN revision: 52401
2010-09-18 06:30:37 +00:00
Lucas De Marchi 69ffdd1b93 Clean it a bit to be easier to understand
SVN revision: 52400
2010-09-18 06:30:30 +00:00
Lucas De Marchi a7fcb37a7f Revert r52345
This function is not needed at all, and as of now it's borken. Coming patches
will properly fix coords on events.



SVN revision: 52398
2010-09-18 06:29:47 +00:00
Lucas De Marchi 251a60ab09 Add function to check if point is inside an object
Add evas_object_inside_get() to check if a certain (x,y) point is inside
an evas_object. This is needed because there's no simple way to
determine it outside of evas when map transformations are used.

For instance, edje uses evas_object_geometry_get() and checks if point is
whithin the rectangle. This is wrong because the object might be
rotated, scaled. Below is a test program:

/**
 * Simple Evas test
 *
 * Compile with: gcc -O0 -g  -o evas_hello_world evas_hello_world.c $(pkg-config --cflags --libs eina evas ecore ecore-evas)
 */
 #include <Eina.h>
 #include <Evas.h>
 #include <Ecore_Evas.h>
 #include <Ecore.h>
 #include <stdio.h>

 #define WIDTH (320)
 #define HEIGHT (240)

Eina_Bool main_signal_exit(void *data, int ev_type, void *ev)
{
    ecore_main_loop_quit();
    return EINA_FALSE;
}

static void
_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
    Evas_Event_Mouse_Up *ev = event_info;
    Eina_Bool b;

    b = evas_object_inside_get(obj, ev->canvas.x, ev->canvas.y);
    fprintf(stderr, "mouse_up: x=%d, y=%d inside=%d\n", ev->canvas.x,
            ev->canvas.y, b);
}

static void
_cb_move(void *data, Evas *e, Evas_Object *obj, void *event_info)
{
    Evas_Event_Mouse_Move *ev = event_info;
    const char *id = data;
    Eina_Bool b;

    b = evas_object_inside_get(obj, ev->cur.canvas.x, ev->cur.canvas.y);
    fprintf(stderr, "[%s] mouse_move: x=%d, y=%d inside=%d\n", id,
            ev->cur.canvas.x, ev->cur.canvas.y, b);
}

int main(void)
{
   Evas *evas;
   Ecore_Evas *window;
   Evas_Object *bg, *r1, *r2;
   Evas_Map *m;

   evas_init();
   ecore_init();
   ecore_evas_init();

   window = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
   if (!evas)
     return -1;

   evas = ecore_evas_get(window);

   bg = evas_object_rectangle_add(evas);
   evas_object_color_set(bg, 255, 255, 255, 255); // white bg
   evas_object_move(bg, 0, 0);                    // at origin
   evas_object_resize(bg, WIDTH, HEIGHT);         // covers full evas
   evas_object_show(bg);

   r1 = evas_object_rectangle_add(evas);
   evas_object_color_set(r1, 255, 0, 0, 255); // 100% opaque red
   evas_object_move(r1, 50, 50);
   evas_object_resize(r1, 100, 100);

   m = evas_map_new(4);
   evas_map_util_points_populate_from_object(m, r1);
   evas_map_util_rotate(m, 45.0, 100, 100);
   evas_map_alpha_set(m, 0);
   evas_map_smooth_set(m, 1);

   evas_object_map_set(r1, m);
   evas_object_map_enable_set(r1, 1);
   evas_map_free(m);
   evas_object_show(r1);
   evas_object_event_callback_add(r1, EVAS_CALLBACK_MOUSE_UP, _cb, NULL);
   evas_object_event_callback_add(r1, EVAS_CALLBACK_MOUSE_MOVE, _cb_move, "r1");

   r2 = evas_object_rectangle_add(evas);
   evas_object_color_set(r2, 0, 255, 0, 255);
   evas_object_move(r2, 210, 150);
   evas_object_resize(r2, 50, 50);
   evas_object_show(r2);
   evas_object_event_callback_add(r2, EVAS_CALLBACK_MOUSE_MOVE, _cb_move, "r2");

   ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, main_signal_exit, evas);

   ecore_evas_show(window);
   ecore_main_loop_begin();

   ecore_evas_free(window);

   ecore_evas_shutdown();
   ecore_shutdown();
   evas_shutdown();

   return 0;
}




SVN revision: 52345
2010-09-16 13:59:46 +00:00
Tom Hacohen 12b55be8af Evas textblock: Added a lot of fixes to evas_textblock_cursor_geometry_get in the case where ctype = EVAS_TEXTBLOCK_CURSOR_BEFORE
SVN revision: 52341
2010-09-16 09:59:39 +00:00
Tom Hacohen 9fb94f209b Evas textblock: Fixed evas_textblock_range_text_get that didn't work on textblocks with no formats at all (not even newlines or tabs).
SVN revision: 52339
2010-09-16 07:12:23 +00:00
Lucas De Marchi 08055d63b9 trivial: spelling in documentation
Some misspellings found in doxy.



SVN revision: 52326
2010-09-15 20:40:51 +00:00
Iván Briano 20ea0eef4e Check there are callbacks before trying to copy them.
Patch by Otávio Pontes


SVN revision: 52323
2010-09-15 19:51:08 +00:00
Cedric BAIL fdc15d4495 * evas: we don't need all the stuff from pthreads to do preload.
SVN revision: 52311
2010-09-15 17:20:37 +00:00
Tom Hacohen 612b3eda81 Evas textblock: fix deleting the first tab in 'a<TAB><TAB>a' that caused weird behavior.
The solution is that we only delete invisible standalones now, not visible ones, this is correct intuitively and of course fixes the bug.

SVN revision: 52302
2010-09-15 14:07:09 +00:00
Tom Hacohen b59743febd Evas textblock: we should also take width of tabs into account when calculating line width.
SVN revision: 52297
2010-09-15 12:45:06 +00:00
Tom Hacohen 8b6083ec26 Evas textblock: Fix and simplify _find_layout_item_line_match which is an helper function used in many parts of textblock.
SVN revision: 52295
2010-09-15 10:24:07 +00:00
Tom Hacohen 108bdeeadd Evas font: removed old (already removed a long time ago) functions from evas_font.h.
SVN revision: 52293
2010-09-15 09:11:19 +00:00
Tom Hacohen 78deeca6ba Evas textblock: Fixed the bug with disappearing text with many tabs and text.
I removed a function that caused the issue and made no sense at all, honestly, it didn't make any sense.
I did a lot of testing trying to see if there are any new bugs after the fix, and nothing, so I guess my instincts were correct.
Please if you can, check out the removed function (_layout_walk_back_to_item_word_redo) and see if it makes any sense to you, if it does, please let me know.

SVN revision: 52243
2010-09-14 13:57:26 +00:00
Iván Briano 2bd045dd1f Pending patch from glima, who's on vacations.
Add two new canvas level callbacks: OBJECT_FOCUS_IN/OUT
As we already had callbacks for objects gaining or losing focus, then
two more for the Canvas, now we can have the entire Evas be notified when
any object changes its focused status. The object in question is passed
as the event_info for the callback.


SVN revision: 52196
2010-09-13 18:04:23 +00:00
Lucas De Marchi 9c091e1714 Assert cache->usage never becomes negative
Assert cache->usage never becomes negative as was occurring before the
fix in r52149.

Just in time, the fix in r52149 was made by Ulisses, not me.



SVN revision: 52190
2010-09-13 13:58:34 +00:00
Lucas De Marchi d32c0f99bd Fix accounting of memory usage in image cache
Memory usage was not accounted right because
cache->func.mem_size_get(ie) returns 0 when called after
cache->func.destructor(ie). Thus the total memory used, kept on
cache->usage, is never decremented in _evas_cache_image_remove_activ()

This implies that cache->usage will keep growing and eventually it will
overflow, becoming negative. So evas_cache_image_flush() will not do its
job because cache->limit (assumed to be positive) will not be less than
cache->usage anymore. So the total memory allocated will start to grow
and the limit won't be respected.

Strictly speaking, it's not a leak, since all the memory will be
eventually freed when evas shutdown is called, but the program might be
killed by over allocating memory. This is caught by valgrind with the
massif tool. The graphic below shows that in the end a huge memory amount
is allocated. This is the moment when cache->usage became negative.

MB
26.04^                                                                   #
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
|                                                                   #::::
| :::::::::::::::::@@:::::::::@:::@::::::@::::::::::::::::::::::::::#::::
| : ::: ::: ::: :::@ :: ::: : @:: @:: :::@: :: ::: : : :: :: : ::: :#::::
0 +----------------------------------------------------------------------->Gi
0                                                                   54.83

This patch is a one line fix, which swaps the calls to
_evas_cache_image_remove_activ() and cache->func.destructor() making
cache->limit to be respected.



SVN revision: 52149
2010-09-10 23:00:26 +00:00
Lucas De Marchi 19c1b1e899 Fix priority dropping
Lowering priority was wrong. Some bugs:

1) You don't lower the priority by setting the scheduler policy to some
   of the real-time ones (SCHED_RR or SCHER_FIFO). If you do so, you are
   actually increasing the priority of the workers and your main thread
   you be preempted and stalled until the workers complete their job.
   Fortunately this will only happen if your programming is running as
   root, as normal users (without CAP_SYS_NICE) are unable to set
   priority to real-time values.

2) setpriority() and getpriority() are not part of pthread and you can't
   use the id returned by pthread. Manpage explicitly says so on
   pthread_self(3):
   "The  thread ID returned by pthread_self() is not the same thing as the
       kernel thread ID returned by a call to gettid(2)."

   Since glibc does not have a gettid, here we are using
   syscall(SYS_gettid)

This patch was tested with the program below. Compile and run:
   $ gcc p_hello2.c -o p_hello2 -lpthread
   $ ./p_hello2 10

You'll see that the main thread remains with its priority and threads
created by the main thread change their own niceness.

 #include <errno.h>
 #include <pthread.h>
 #include <sched.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/resource.h>
 #include <sys/syscall.h>
 #include <sys/time.h>
 #include <sys/types.h>

/* Lower priority of current thread.
 *
 * It's used by worker threads so they use up "bg cpu" as it was really intended
 * to work. If current thread is running with real-time priority, we decrease
 * our priority by 5. This is done in a portable way.  Otherwise we are
 * running with SCHED_OTHER policy and there's no portable way to set the nice
 * level on current thread. In Linux, it does work and it's the only one that is
 * implemented.
 */
static void
_ecore_thread_pri_drop(void)
{
   struct sched_param param;
   int pol, prio, ret;
   pid_t tid;
   pthread_t pthread_id;

   pthread_id = pthread_self();
   ret = pthread_getschedparam(pthread_id, &pol, &param);
   if (ret)
     {
        fprintf(stderr, "Unable to query sched parameters\n");
        return;
     }

   if (pol == SCHED_RR || pol == SCHED_FIFO)
     {
        prio = sched_get_priority_max(pol);
        param.sched_priority += 5;
        if (prio > 0 && param.sched_priority > prio)
           param.sched_priority = prio;

        pthread_setschedparam(pthread_id, pol, &param);
     }
 #ifdef __linux__
   else
     {
        tid = syscall(SYS_gettid);
        errno = 0;
        prio = getpriority(PRIO_PROCESS, tid);
        if (errno == 0)
          {
             prio += 5;
             if (prio > 19)
                prio = 19;

             setpriority(PRIO_PROCESS, tid, prio);
          }
     }
 #endif
}

/*
 * p_hello.c -- a hello program (in pthread)
 */
 #define MAX_THREAD 1000

typedef struct {
    int id;
} parm;

void *hello(void *arg)
{
    parm *p=(parm *)arg;
    pid_t tid;
    int prio;
    tid =  syscall(SYS_gettid);
    printf("[%d] Hello from node %d\n", tid, p->id);
    pthread_yield();

    printf("[%d] HELLO!\n", tid);

    _ecore_thread_pri_drop();

    prio = getpriority(PRIO_PROCESS, tid);
    printf("[%d] New nice value: %d\n", tid, prio);
    return (NULL);
}

int main(int argc, char* argv[]) {
    int n,i;
    pthread_t *threads;
    pthread_attr_t pthread_custom_attr;
    parm *p;

    pid_t tid;
    int prio;

    if (argc != 2)
    {
        printf ("Usage: %s n\n  where n is no. of threads\n",argv[0]);
        exit(1);
    }

    n=atoi(argv[1]);

    if ((n < 1) || (n > MAX_THREAD)) {
        printf ("The no of thread should between 1 and %d.\n",MAX_THREAD);
        exit(1);
    }

    threads = (pthread_t *)malloc(n * sizeof(*threads));
    pthread_attr_init(&pthread_custom_attr);

    p = (parm *)malloc(n * sizeof(parm));
    /* Start up thread */

    tid = syscall(SYS_gettid);
    for (i=0; i<n; i++) {
        prio = getpriority(PRIO_PROCESS, tid);
        printf("[%d] root thread nice value: %d\n", tid, prio);

        p[i].id=i;
        pthread_create(&threads[i], &pthread_custom_attr, hello, (void *)(p+i));
    }

    /* Synchronize the completion of each thread. */

    for (i=0; i<n; i++) {
        pthread_join(threads[i],NULL);
    }
    free(p);

    return 0;
}



SVN revision: 52040
2010-09-09 12:45:39 +00:00
Carsten Haitzler 9a4aa69e71 return NULL after if to avoid other lku
SVN revision: 52033
2010-09-09 07:27:56 +00:00
Carsten Haitzler 40e57dd2d7 that should have been an LKU
SVN revision: 52032
2010-09-09 07:23:55 +00:00
Carsten Haitzler 5f6add7b2f and some final fixes anc cleanups - tested.
SVN revision: 52031
2010-09-09 07:14:11 +00:00
Carsten Haitzler c4ee82f6a7 lots of cleanups... actually tested! :)
SVN revision: 52030
2010-09-09 07:08:10 +00:00
Carsten Haitzler 679d566fde actually revert that - not enough testing. need to work on it.
SVN revision: 52029
2010-09-09 06:36:01 +00:00
Carsten Haitzler 4975395633 major clean of the preload stuff. leaks. bugs. nastinessesssss...
SVN revision: 52028
2010-09-09 06:31:29 +00:00
Brett Nash c69628f5af Whitespace --;
SVN revision: 52024
2010-09-09 05:36:56 +00:00