00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #define SED_COMPACTION_PROC_NAME "compaction"
00022 #define EH_LOG_DOMAIN SED_COMPACTION_PROC_NAME
00023
00024 #include <stdio.h>
00025 #include <pthread.h>
00026 #include <sed/sed_sedflux.h>
00027 #include "my_processes.h"
00028
00029 #undef WITH_THREADS
00030
00031 #define N_THREADS 5
00032
00033 void thread_compact( void *data , void *user_data );
00034 int compact(Sed_column,double);
00035
00036 Sed_process_info
00037 run_compaction( Sed_process proc , Sed_cube p )
00038 {
00039 Sed_process_info info = SED_EMPTY_INFO;
00040
00041 #if !defined(WITH_THREADS)
00042
00043 {
00044 gint i;
00045 gint len = sed_cube_size(p);
00046 for ( i=0 ; i<len ; i++ )
00047 compact( sed_cube_col(p,i) , sed_cube_age_in_years(p) );
00048 }
00049
00050 #else
00051
00052 if (!g_thread_supported ()) g_thread_init(NULL);
00053
00054 {
00055 GError *error=NULL;
00056 GThreadPool *compact_pool;
00057
00058 compact_pool = g_thread_pool_new( (GFunc)&thread_compact ,
00059 (gpointer)p ,
00060 N_THREADS ,
00061 TRUE ,
00062 &error );
00063
00064 eh_require( error==NULL );
00065 {
00066 gint i;
00067 gint* queue;
00068 gssize len = sed_cube_size(p);
00069
00070 queue = eh_new( int , len );
00071 for ( i=0 ; i<len ; i++ )
00072 {
00073 queue[i] = i;
00074 g_thread_pool_push( compact_pool , &(queue[i]) , &error );
00075 eh_require( error==NULL );
00076 }
00077 g_thread_pool_free( compact_pool , FALSE , TRUE );
00078 eh_free( queue );
00079 }
00080 }
00081
00082 #endif
00083
00084 return info;
00085 }
00086
00087 int pthread_mutex_spinlock(pthread_mutex_t *mutex);
00088
00089 void thread_compact( void *data , void *user_data )
00090 {
00091 Sed_cube p = (Sed_cube)user_data;
00092 int i = *((int*)data);
00093
00094 compact( sed_cube_col(p,i) , sed_cube_age_in_years(p) );
00095
00096 return;
00097 }
00098
00099 #define S_NTRIES 5
00100
00101 int pthread_mutex_spinlock(pthread_mutex_t *mutex)
00102 {
00103 int i=0;
00104 while ( i++<S_NTRIES )
00105 {
00106 if ( pthread_mutex_trylock(mutex)==0 )
00107 return 0;
00108 }
00109 return pthread_mutex_lock(mutex);
00110 }
00111