00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mtm_i.h"
00034 #include "useraction.h"
00035
00036 #define USERACTION_LIST_SIZE 8
00037
00038 typedef struct mtm_user_action_s mtm_user_action_t;
00039
00040 struct mtm_user_action_s
00041 {
00042 _ITM_userCommitFunction fn;
00043 void *arg;
00044 };
00045
00046 struct mtm_user_action_list_s
00047 {
00048 mtm_user_action_t *array;
00049 int nb_entries;
00050 int size;
00051 };
00052
00053
00054
00055 int
00056 mtm_useraction_list_alloc(mtm_user_action_list_t **listp)
00057 {
00058 mtm_user_action_list_t *list;
00059
00060 list = (mtm_user_action_list_t *) malloc (sizeof(mtm_user_action_list_t));
00061
00062 if (list) {
00063 list->array = (mtm_user_action_t *) realloc(NULL, sizeof(mtm_user_action_t) * USERACTION_LIST_SIZE);
00064 list->size = USERACTION_LIST_SIZE;
00065 *listp = list;
00066 return 0;
00067 }
00068
00069 listp = NULL;
00070 return -1;
00071 }
00072
00073
00074 int
00075 mtm_useraction_list_free(mtm_user_action_list_t **listp)
00076 {
00077 assert(listp != NULL);
00078
00079 mtm_user_action_list_t *list = *listp;
00080
00081 if (list) {
00082 free (list->array);
00083 free (list);
00084 }
00085 *listp = NULL;
00086
00087 return 0;
00088 }
00089
00090
00091
00092 int
00093 mtm_useraction_clear(mtm_user_action_list_t *list)
00094 {
00095 assert(list != NULL);
00096
00097 list->nb_entries = 0;
00098
00099 return 0;
00100 }
00101
00102
00103 void
00104 mtm_useraction_list_run (mtm_user_action_list_t *list, int reverse)
00105 {
00106 mtm_user_action_t *action;
00107 int i;
00108
00109 for (i=0; i<list->nb_entries; i++) {
00110 if (reverse) {
00111 action = &list->array[list->nb_entries - i - 1];
00112 } else {
00113 action = &list->array[i];
00114 }
00115 action->fn (action->arg);
00116 }
00117 }
00118
00119
00120 void
00121 mtm_useraction_addUserCommitAction(mtm_tx_t * tx,
00122 _ITM_userCommitFunction fn,
00123 _ITM_transactionId tid,
00124 void *arg)
00125 {
00126 mtm_user_action_list_t *list = tx->commit_action_list;
00127 mtm_user_action_t *action;
00128
00129 if (list->nb_entries == list->size) {
00130 list->size *= 2;
00131 list->array = (mtm_user_action_t *) realloc(list->array, sizeof(mtm_user_action_t) * list->size);
00132 }
00133
00134 action = &list->array[list->nb_entries++];
00135 action->fn = fn;
00136 action->arg = arg;
00137 }
00138
00139
00140 void
00141 mtm_useraction_addUserUndoAction(mtm_tx_t * tx,
00142 const _ITM_userUndoFunction fn,
00143 void *arg)
00144 {
00145 mtm_user_action_list_t *list = tx->undo_action_list;
00146 mtm_user_action_t *action;
00147
00148 if (list->nb_entries == list->size) {
00149 list->size *= 2;
00150 list->array = (mtm_user_action_t *) realloc(list->array, sizeof(mtm_user_action_t) * list->size);
00151 }
00152
00153 action = &list->array[list->nb_entries++];
00154 action->fn = fn;
00155 action->arg = arg;
00156 }